Url coding 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

': invalid format: "2015-06-15T14: 45: 21.982600 00:00" incorrectly formed at "00:00"

And the system will show me this error. Since I want to encode this format: 2015-06-15T14% 3A45% 3A21.982600% 2B00% 3A00

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

from

How to transfer request in Python?

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

he works with it!

0
source

All Articles