python - 在使用 Google Places api 时,我可以做些什么来解决这个错误“raise googlemaps.exceptions.Timeout()”?
问题描述
我必须得到一些地方的一些细节。我在 Python 中编写了一个代码,以使用 Google Places API 自动执行此操作。我使用了两个查询来自动化这个功能。它们是“附近搜索”和“地点详情”。执行程序后,我可以获得一些地方的详细信息。但是,在执行程序时,googlemaps.exceptions.Timeout
发生了异常。我尚未启用结算功能。这是我的代码中的问题还是其他问题?启用计费后会解决此错误吗?
gmaps = googlemaps.Client(key = API_Key)
def search_places(location, radius, type):
places = gmaps.places_nearby(location = location, radius = radius, type = type)
time.sleep(3)
pprint.pprint(places)
for place in places['results']:
place_id = place['place_id']
fields = ['name', 'formatted_address', 'formatted_phone_number', 'rating', 'website']
place_details = gmaps.place(place_id = place_id, fields = fields)
pprint.pprint(place_details)
time.sleep(3)
search_places('40.712776,-74.005974', '20000', 'restaurant')
错误是:
raise googlemaps.exceptions.Timeout()
解决方案
您确实需要为 Places API 启用计费功能。查看Google 的结算文档。
提醒:要使用 Places API,您必须在所有 API 请求中包含一个 API 密钥,并且您必须为每个项目启用计费。
希望这可以帮助。
推荐阅读
- javascript - 如何在 Swift 中将 multipart/form-data 请求发送到此 API 片段
- excel - 函数 Dir() 无法正常工作:错误代码 5:无效的参数或过程调用
- primeng - PrimeNG Spinner 中的 DecimalSeparator 不起作用
- android - 我不去下一个活动?
- jquery - 如何禁用未绑定事件
- react-router - 如何反应路线路径一/二/三?
- java - 如何将文件/位图上传到 Cloud Firestore?
- json - 确定用于简单时间跟踪应用程序的数据模型
- vba - 格式化 SentOn 以仅显示日期
- c# - 将 Null-Propagation 运算符与 null-coalescing-operator 一起使用以引发空异常