Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python urlencode don't encode special characters

I'm forming a post request.

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

This will result into

key1=value%401&key2=value%402

What I really want is

key1=value@1&key2=value@2

Any other way to this?

like image 722
Ganesh Satpute Avatar asked Jul 17 '15 05:07

Ganesh Satpute


1 Answers

If you want to do your own thing, you'll 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?

like image 105
John La Rooy Avatar answered Oct 19 '22 03:10

John La Rooy