I'm trying to use the Google Maps geocoder with Python and JSON, but keep being told I have a bad request:
add = "Buckingham Palace, London, SW1A 1AA"
geocode_url = "https://maps.googleapis.com/maps/api/geocode/json?address=%s&sensor=false®ion=uk" % add
print geocode_url
req = urllib2.urlopen(geocode_url)
jsonResponse = json.loads(f.read())
pprint.pprint(nest)
This fails with urllib2.HTTPError: HTTP Error 400: Bad Request
.
But if I simply copy and paste
https://maps.googleapis.com/maps/api/geocode/json?address=Buckingham%20Palace,%20London,%20SW1A%201AA&sensor=false®ion=uk
into a browser bar, it works fine.
What is wrong with my request?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…