how to urlencode a value that is a python dictionary with encoded unicode characters -
i'm trying make url-encoded web request in python 2.7 want send list of python dictionaries on server decoded list of json objects. in essence i'm making:
>>>urllib.urlencode({"param":"val", "items":[item1, item2] }, true)
where item1 can { "a": u"ลก".encode("utf8") } (simplified example)
the problem arises because of unicode characters.
if item1 encoded, meaningful:
>>>urllib.urlencode(item1) 'a=%c5%a1' however, if call urllib.urlencode({"test": item1}) mess:
'test=%7b%27a%27%3a+%27%5cxc5%5cxa1%27%7d' in case, unicode character no longer encoded %c5%a1 longer sequence incorrectly decoded on server side.
does have suggestion how transform complex dictionary values (i.e. item1) before calling urlencode avoid issue?
one way or need decode encoded before re-encoding here 1 approach:
dictionary = {"test": item1} urllib.urlencode(dict([(k, decode_operation(v)) k, v in dictionary.iteritems()]))
Comments
Post a Comment