Dan
Dan

Reputation: 6573

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

Upvotes: 1

Views: 501

Answers (1)

catavaran
catavaran

Reputation: 45575

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

Upvotes: 2

Related Questions