Python urlencode does not encode special characters

I form a mail request.

mydict = {'key1': 'value@1', 'key2': 'value@2'}
encoded_dict = urllib.urlencode(mydict)

This will lead to

key1=value%401&key2=value%402

I really want

key1=value@1&key2=value@2

Any other way of doing this?

+4
source share
1 answer

If you want to do your job, you will have to write your own encoder. eg:

mydict = {'key1': 'value@1', 'key2': 'value@2'}
>>> "&".join("{}={}".format(*i) for i in mydict.items())
'key2=value@2&key1=value@1'

But why not just use JSON?

0
source

Source: https://habr.com/ru/post/1598323/


All Articles