lscena
lscena

Reputation: 409

URL encode & decode

Is there some plug-in or library to encode and decode URLs?

For example im doing that:

name='Jazmín Fernández'
self.redirect('/page?userName='+name)

But, obviously there are some characters that need to be encoded (í, á, and the space between n and F). So, this give me an error.

Thanks!!!

Upvotes: 0

Views: 492

Answers (1)

Alex Mendes da Costa
Alex Mendes da Costa

Reputation: 56

You should convert your unicode string to UTF8, before passing it to urllib.urlencode.

>>> name = u'Jazmín Fernández'
>>> urllib.urlencode({'name': name.encode('utf8')})
'name=Jazm%C3%ADn+Fern%C3%A1ndez'

Upvotes: 3

Related Questions