开发者

Django - Receiving JSON from Google Maps API

开发者 https://www.devze.com 2023-04-12 07:44 出处:网络
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\'

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'))
0

精彩评论

暂无评论...
验证码 换一张
取 消