首页 > 解决方案 > 在使用 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()

标签: pythongoogle-mapsgoogle-maps-api-3google-places-api

解决方案


确实需要为 Places API 启用计费功能。查看Google 的结算文档

提醒:要使用 Places API,您必须在所有 API 请求中包含一个 API 密钥,并且您必须为每个项目启用计费

希望这可以帮助。


推荐阅读