Search code examples
pythonescapingurllib2urlencode

How to properly url encode accents?


I need to url encode foreign names, like "Misère".

When I do:

urllib2.quote(name)

I get a the error:

File "/System/Library/Frameworks/Python.framework/Versions/
2.5/lib/python2.5/urllib.py", line 1205, in quote
    res = map(safe_map.__getitem__, s)
KeyError: u'\xe8'

What am I doing wrong?


Solution

  • Try:

    urllib2.quote(s.encode('utf8'))