Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #4905
| From | Marian Steinbach <marian@sendung.de> |
|---|---|
| Date | 2011-05-07 14:24 +0200 |
| Subject | Stuck with urllib.quote and Unicode/UTF-8 |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1287.1304771096.9059.python-list@python.org> (permalink) |
Hi!
I am stuck with calling URLs with parameters containing non-ASCII
characters. I'm creating a url like this.
url = 'http://maps.googleapis.com/maps/api/geocode/json?address=' +
urllib.quote(address) + '&sensor=false&language=DE'
address can be a string like u"Köln, Nordrhein-Westfalen". This results in
http://maps.googleapis.com/maps/api/geocode/json?address=K%F6ln%2C%20Nordrhein-Westfalen&sensor=false&language=DE
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
http://maps.googleapis.com/maps/api/geocode/xml?address=K%C3%B6ln,%20Nordrhein-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 = 'http://maps.googleapis.com/maps/api/geocode/json?address=' +
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"?
Thanks!
Marian
Back to comp.lang.python | Previous | Next | Find similar
Stuck with urllib.quote and Unicode/UTF-8 Marian Steinbach <marian@sendung.de> - 2011-05-07 14:24 +0200
csiph-web