Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python URL decoding?

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.

like image 296
user1886965 Avatar asked Dec 08 '12 01:12

user1886965


People also ask

How do I decode a URL in Python 3?

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.

How do I remove 20 from a URL in Python?

replace('%20+', '') will replace '%20+' with empty string.


1 Answers

Simply try to decode it:

urllib2.unquote('%C3%B8').decode('utf-8')   # --> 'ø'
like image 118
VisioN Avatar answered Sep 22 '22 16:09

VisioN