zoukankan      html  css  js  c++  java
  • Encode query with Python

    Encode query with Python - WABI

        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

  • 相关阅读:
    Typescript类、命名空间、模块
    TypeScript 基础类型、变量声明、函数、联合类型、接口
    JS中的单线程与多线程、事件循环与消息队列、宏任务与微任务
    wangEditor上传本地视频
    java版excel转pdf,word转pdf
    idea2019.3 没有 Autoscroll from Source
    mysql 实现类似oracle函数bitand功能
    spring boot 配置文件动态更新原理 以Nacos为例
    spring boot 发布自动生成svn版本号
    spring boot JPA 数据库连接池释放
  • 原文地址:https://www.cnblogs.com/lexus/p/2405379.html
Copyright © 2011-2022 走看看