python - 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 中启用了。我会错过什么?
解决方案
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 密钥。
推荐阅读
- python - Html 选择 POST Django
- rust - Rust 宏接受带有冒号的参数,一个位于模块内部的结构
- php - $wpdb->insert() 抛出“外键约束失败”错误
- flutter - 从 Dart 中的另一个文件导入扩展方法
- sparql - 无法通过 GraphDB API 从 URL 加载一些本体
- jointjs - JointJS:joint.dia.Graph.prototype.clear 不起作用
- sql - 两个日期之间的时间,不包括晚上和周末?
- ruby-on-rails - Active Record - Rails 6,拥有两个不相关模型使用的模型
- c# - 我怎么知道我的 DLL 中的函数是从 azure 函数还是简单的 Web 应用程序调用的
- python - 使用 pytorch 分组卷积获取错误