Url 使用 python 2.7 编码

Url encode using python 2.7

>>> import httplib
>>> x = httplib.HTTPConnection('localhost', 8080)
>>> x.connect()
>>> x.request('GET','/camera/store?fn=aaa&ts='+str.encode('2015-06-15T14:45:21.982600+00:00','ascii')+'&cam=ddd')
>>> y=x.getresponse()
>>> z=y.read()
>>> z

'error: Invalid format: "2015-06-15T14:45:21.982600 00:00" is malformed at " 00:00"'

系统向我显示了这个错误。因为我想将此格式编码为:2015-06-15T14%3A45%3A21.982600%2B00%3A00

>>> import urllib
>>> f = { 'fn' : 'aaa', 'ts' : "2015-06-15T14:45:21.982600+00:00"}
>>> urllib.urlencode(f)

来自:

How to urlencode a querystring in Python?

url = "http://example.com?p=" + urllib.quote(query)

它适用于此!