In javascript I do the following:
encodeURIComponent(comments)
while in Python i do the following:
urllib2.unquote(comments)
For some reason, when I do the following:
encodedURIComponents('ø')
I get %C3%B8
, but when I decode
urllib2.unquote('%C3%B8')
I get ø
instead of ø
, which is the original character.
What gives?
I'm on a platform that uses jQuery on client side, and Python/Django server side.
In Python 3+, You can URL decode any string using the unquote() function provided by urllib. parse package. The unquote() function uses UTF-8 encoding by default.
replace('%20+', '') will replace '%20+' with empty string.
Simply try to decode it:
urllib2.unquote('%C3%B8').decode('utf-8') # --> 'ø'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With