Django - Receiving JSON from Google Maps API
I am trying to retrieve some data from the Google Maps API from a Django app.
req = 'http://maps.google.com/maps/nav?q=from:London%20to:Manchester'
data = urllib.urlopen(req).read()
jsondata = simplejson.loads(data)
However, the above gives me the following error:
UnicodeDecodeError: 'utf8' codec can't decode byte 0xa9 in position 9: 开发者_运维技巧unexpected code byte.
Is there an easy way around this?
Any advice appreciated.
Thanks
Google maps returns response in ISO-8859-1 encoding. You need to decode the data
bytestring before passing it to simplejson:
jsondata = simplejson.loads(data.decode('ISO-8859-1'))
精彩评论