首页 > 解决方案 > Google Maps Places 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 中启用了。我会错过什么?

标签: pythongoogle-mapsgoogle-api

解决方案


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

原因:请求 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

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


推荐阅读