调用含中文参数Http接口

发送http请求,参数含有中文时,需要对参数值处理

url = "http://xxxx:8080/itemclass.php?text="
def request(spu_name):
    res = None
    try:
        requrl = url + urllib.quote(spu_name)
        req = urllib2.Request(requrl)
        res = urllib2.urlopen(req).read()
    except Exception, ex:
        print >> sys.stderr, ex
        sys.stderr.write("request data error, %s\n" % (url + spu_name))
    return res

你可能感兴趣的:(Python)