Url encode using python 2.7
Asked Answered
I

2

8
>>> 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"'

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

Injurious answered 31/5, 2016 at 9:9 Comment(0)
G
9
>>> import urllib
>>> f = { 'fn' : 'aaa', 'ts' : "2015-06-15T14:45:21.982600+00:00"}
>>> urllib.urlencode(f)

from:

How to urlencode a querystring in Python?

Gesticulation answered 31/5, 2016 at 9:14 Comment(1)
Just: x.request('GET','/camera/store?fn=aaa&ts='+urllib.urlencode(f)+'&cam=ddd'), also add cam and 'ddd' to the data...Gesticulation
I
4
url = "http://example.com?p=" + urllib.quote(query)

it works with this!

Injurious answered 31/5, 2016 at 9:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.