Stuck with urllib.quote and Unicode/UTF-8

  • Thread starter Marian Steinbach
  • Start date


Marian Steinbach


I am stuck with calling URLs with parameters containing non-ASCII
characters. I'm creating a url like this.

url = '' +
urllib.quote(address) + '&sensor=false&language=DE'

address can be a string like u"Köln, Nordrhein-Westfalen". This results in

and this doesn't seem to meet Google's Encoding expectations. I get an
"INVALID REQUEST" response. (The same things works if there are only
ASCII characters in the address.)

When I manually enter the "Köln"... string in the Firefox address bar,
Firefox makes the URL Nordrhein-Westfalen&sensor=false&language=DE

out of this and it works fine. %C3%B6 seems to be the url-encoded
representation of an UTF-8 representation of a "ö" character.

So the next thing I tried is to get address utf-8-encoded, like this:

url = '' +
urllib.quote(address.encode('utf-8')) + '&sensor=false&language=DE'

This gives me an error like

UnicodeDecodeError: 'ascii' codec can't decode byte 0xf6 in position
1: ordinal not in range(128)

Again, the input string for address is u"Köln, Nordrhein-Westfalen".

Can you see what I'm doing wrong or what I would have to to to get
from u"ö" to "%C3%B6"?




Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question