博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Encode query with Python
阅读量:5873 次
发布时间:2019-06-19

本文共 1681 字,大约阅读时间需要 5 分钟。

    Encode query with Python
    From WABI
    Jump to: navigation, search
    Contents
    [hide]
        1 Summary
        2 Description
        3 Sample program
        4 Link
    Summary
    Result may not be able to be retrieved normally, if query including non alphanumeric character is used with Python.
    Description
    You have to encode your query. If qPath is a query to be encoded, please do as follows.
    import urllib
    urllib.urlencode({'<parameter_name>':qPath,})
    Sample program
    This tutorial introduces a example that retrieve entries which feature-key is 'rRNA', qualifier name is 'product' and has '16s ribosomal RNA' in qualifier value with searchByXMLPath of ARSA.
    Download this program
    import socket
    import urllib
    #set server
    host = "xml.nig.ac.jp"
    port =  80
    #set API server
    url = "/rest/Invoke"
    qPath = "/ENTRY/DDBJ/feature-table/feature/f_key=='rRNA' AND "
    qPath = qPath + "(/ENTRY/DDBJ/feature-table/feature{/f_key=='rRNA' AND "
    qPath = qPath + "/f_quals/qualifier{/q_name=='product' AND /q_value='16S ribosomal RNA'}}) "
    rPath = "/ENTRY/DDBJ/primary-accession,/ENTRY/DDBJ/definition"
    offset = "1";
    count = "10";
    query = urllib.urlencode({'queryPath':qPath,'returnPath':rPath,'offset':offset,'count':count});
    #set parameter
    query = "service=ARSA&method=searchByXMLPath&"+ query;
    #make connection
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    try:
        sock.connect((host, port))
        sock.send("POST " + url + " HTTP/1.0\n")
        sock.send("Content-Type: application/x-www-form-urlencoded\n")
        sock.send("User-Agent: python/socket\n")
        sock.send("Content-Length:" + `len(query)` + "\n\n")
        sock.send(query)
    except socket.error, e:
        print 'Error: %s' % e
    while 1:
        rcvmsg = sock.recv(1024)
        print rcvmsg,
        if rcvmsg == :
            break
    sock.close

转载地址:http://nyhnx.baihongyu.com/

你可能感兴趣的文章
视图、索引、存储过程优缺点
查看>>
百度地图接口调用
查看>>
javascript正则表达式<一>
查看>>
WCF学习笔记
查看>>
CQRS
查看>>
MySQL - 行锁 表锁 乐观锁 悲观锁 读锁 写锁
查看>>
如何解决iOS界面操作导致导致NSTimer暂停计时的问题?
查看>>
Mac os x 系统的发展史
查看>>
WinForm基础
查看>>
初学类和对象
查看>>
XML 反序列化为Model
查看>>
一些感想
查看>>
SDL2 undefined reference to `SDL_Init' 问题
查看>>
蓝天集团董事长郎凤娥专访
查看>>
类成员与方法访问控制从严
查看>>
JSF是什么?它与Struts是什么关系?
查看>>
51 nod 1405 树的距离之和
查看>>
BZOJ 2733: [HNOI2012]永无乡
查看>>
spring 线程安全
查看>>
面试十大难题的样板回答
查看>>