我正在尝试使用下面的代码,但它不起作用。
from googlemaps import GoogleMaps
gmaps = GoogleMaps(api_key='mykey')
reverse = gmaps.reverse_geocode(38.887563, -77.019929)
address = reverse['Placemark'][0]['address']
print(address)
当我尝试运行此代码时,我遇到了以下错误。请帮助我解决问题。
Traceback (most recent call last):
File "C:/Users/Gokul/PycharmProjects/work/zipcode.py", line 3, in <module>
reverse = gmaps.reverse_geocode(38.887563, -77.019929)
File "C:\Python27\lib\site-packages\googlemaps.py", line 295, in reverse_geocode
return self.geocode("%f,%f" % (lat, lng), sensor=sensor, oe=oe, ll=ll, spn=spn, gl=gl)
File "C:\Python27\lib\site-packages\googlemaps.py", line 259, in geocode
url, response = fetch_json(self._GEOCODE_QUERY_URL, params=params)
File "C:\Python27\lib\site-packages\googlemaps.py", line 50, in fetch_json
response = urllib2.urlopen(request)
File "C:\Python27\lib\urllib2.py", line 127, in urlopen
return _opener.open(url, data, timeout)
File "C:\Python27\lib\urllib2.py", line 410, in open
response = meth(req, response)
File "C:\Python27\lib\urllib2.py", line 523, in http_response
'http', request, response, code, msg, hdrs)
File "C:\Python27\lib\urllib2.py", line 448, in error
return self._call_chain(*args)
File "C:\Python27\lib\urllib2.py", line 382, in _call_chain
result = func(*args)
File "C:\Python27\lib\urllib2.py", line 531, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 403: Forbidden