gpt4 book ai didi

python - 谷歌地图 API 的命中率限制,但不知道为什么

转载 作者:太空狗 更新时间:2023-10-29 21:35:26 24 4
gpt4 key购买 nike

我编写了一个脚本来将地址发送到 Google Maps 的 API 并接收回 Lat 和 Lng。但是,我收到错误消息,指出我在 20 次左右的查询后超出了 Google 的速率限制。有什么我没有考虑的吗?

如果有任何帮助,我将不胜感激。我在使用 API 方面还很陌生,所以更好地理解我达到速率限制的原因会非常有帮助。

从名为 Location 的 csv 文件中读取地址后,下面是我的相关代码。

    for row in locations:
address = 'XXX, New Haven, CT'
first = re.search('^(.*),',row[0])
address = re.sub('XXX',first.group(), address)
lat, lng = gmaps.address_to_latlng(address)

下面是我的错误信息。

    Traceback (most recent call last):
File "<input>", line 5, in <module>
File "/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/googlemaps-1.
0.2-py2.7.egg/googlemaps.py", line 310, in address_to_latlng
return tuple(self.geocode(address)['Placemark'][0]['Point']['coordinates'][1
::-1])
File "/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/googlemaps-1.
0.2-py2.7.egg/googlemaps.py", line 262, in geocode
raise GoogleMapsError(status_code, url, response)
GoogleMapsError: Error 620: G_GEO_TOO_MANY_QUERIES

最佳答案

每次 gmaps.address_to_latlng 调用都会向 Google 服务器发送一个请求,您只能发出有限数量的请求。

Google 的文档 usage limits :

Use of the Google Geocoding API is subject to a query limit of 2,500 geolocation requests per day. [...] Additionally, we enforce a request rate limit to prevent abuse of the service.

还有 docs on G_GEO_TOO_MANY_QUERIES :

The given key has gone over the requests limit in the 24 hour period or has submitted too many requests in too short a period of time. If you're sending multiple requests in parallel or in a tight loop, use a timer or pause in your code to make sure you don't send the requests too quickly.

所以,按照他们告诉你的去做:

import time

# And then in the loop, pause:
time.sleep(1)

将“1”调整为适当的秒数,这样您就不会用完允许的请求。

关于python - 谷歌地图 API 的命中率限制,但不知道为什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7643296/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com