Google Maps Places API未经授权的错误

时间:2018-06-19 15:19:57

标签: python google-maps google-api

我正在尝试使用Places API来获取城市中餐厅的列表。我不断收到此错误:

Traceback (most recent call last):
  File "googlePlacesAPI.py", line 10, in <module>
    radius=20000, types=[types.TYPE_FOOD])
  File "/Users/**me**/Downloads/slimkrazy-python-google-places-d4b7363/googleplaces/__init__.py", line 281, in nearby_search
    lat_lng_str = self._generate_lat_lng_string(lat_lng, location)
  File "/Users/**me**/Downloads/slimkrazy-python-google-places-d4b7363/googleplaces/__init__.py", line 593, in _generate_lat_lng_string
    'lat_lng must be a dict with the keys, \'lat\' and \'lng\'. Cause: %s' % str(e))
ValueError: lat_lng must be a dict with the keys, 'lat' and 'lng'. Cause: Request to URL https://maps.googleapis.com/maps/api/geocode/json?sensor=false&key=YOUR_API_KEY&address=%7B%27lat%27%3A+%2733.7490%27%2C+%27lng%27%3A+%2784.3880%27%7D failed with response code: REQUEST_DENIED

我相信这是我的API密钥无法运行的结果,尽管已在Google Developer Console中启用了该密钥。我可能会缺少什么?

1 个答案:

答案 0 :(得分:0)

ValueError: lat_lng必须是键为“ lat”和“ lng”的字典。

原因: 请求网址

https://maps.googleapis.com/maps/api/geocode/json?sensor=false&key=**YOUR_API_KEY**&address=%7B%27lat%27%3A+%2733.7490%27%2C+%27lng%27%3A+%2784.3880%27%7D failed with response code: REQUEST_DENIED

因此,对象必须采用 {key:value,key:value} 格式,并且您的URL必须具有有效的 API KEY 。您需要使用实际的API密钥替换该key=YOUR_API_KEY