This is ridiculous .. I am trying to read geo-search data from openstreetmap. The code that executes the request is as follows:
params = urllib.urlencode({'q': ",".join([e for e in full_address]), 'format': "json", "addressdetails" : "1"}) query = "http://nominatim.openstreetmap.org/search?%s" % params print query time.sleep(5) response = json.loads(unicode(urllib.urlopen(query).read(), "UTF-8"), encoding="UTF-8") print response
The request for ZΓΌrich is correctly encoded with UTF-8 URLs. There are no miracles here.
http://nominatim.openstreetmap.org/search?q=Z%C3%BCrich%2CSWITZERLAND&addressdetails=1&format=json
When I print the answer, u with umlaut encoded latin1 (0xFC)
[{u'display_name': u'Z\xfcrich, Bezirk Z\xfcrich, Z\xfcrich, Schweiz, Europe', u'place_id': 588094, u'lon': 8.540443
but this is nonsense because openstreetmap returns JSON data in UTF-8
Connecting to nominatim.openstreetmap.org (nominatim.openstreetmap.org)|128.40.168.106|:80... connected. HTTP request sent, awaiting response... HTTP/1.1 200 OK Date: Wed, 26 Jan 2011 13:48:33 GMT Server: Apache/2.2.14 (Ubuntu) Content-Location: search.php Vary: negotiate TCN: choice X-Powered-By: PHP/5.3.2-1ubuntu4.7 Access-Control-Allow-Origin: * Content-Length: 3342 Keep-Alive: timeout=15, max=100 Connection: Keep-Alive Content-Type: application/json; charset=UTF-8 Length: 3342 (3.3K) [application/json]
which is also confirmed by the contents of the file, and then I directly say that it is UTF-8 both in reading and in json analysis.
What's going on here?
EDIT : apparently this is json.loads, which is somehow screwed.