I am facing a problem with urllib.url_encode in python. Bets explained with some code:
>>> from urllib import urlencode
>>> params = {'p' : '1 2 3 4 5&6', 'l' : 'ab|cd|ef'}
>>> urlencode(params)
'p=1+2+3+4+5%266&l=ab%7Ccd%7Cef'
I want to keep the pipes (‘|’) in to l parameter. can you please tell me how?
The result should be
'p=1+2+3+4+5%266&l=ab|cd|ef'
PS: I do not want to put together the URL manually, but use urlencode for that.
Thanks
-Pat
The urlencode() method is acting as expected. If you want to prevent the encoding then you can first encode the entire object and then replace the encoded characters with pipes.