首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Google : OVER_QUERY_LIMIT问题是断断续续的

Google : OVER_QUERY_LIMIT问题是断断续续的
EN

Stack Overflow用户
提问于 2020-01-23 03:26:30
回答 2查看 554关注 0票数 0

我知道以前有人问过这个问题,但我的问题与其他问题略有不同。

我编写了一个python脚本来读取随机地址并返回它们的位置ID。

这是我的密码:

代码语言:javascript
运行
复制
from googleplaces import GooglePlaces
import pandas as pd
import time
import xlrd
YOUR_API_KEY = <my_key>

google_places = GooglePlaces(YOUR_API_KEY)
loc = r"C:\Users\user\Desktop\test.xlsx"

wb = xlrd.open_workbook(loc)
sheet = wb.sheet_by_index(0)

for i in range(1,sheet.nrows):
    read_address = sheet.cell_value(i,0)
    query_result = google_places.text_search(
        query=''+read_address)
    for place in query_result.places:
        print(place.name)
        print(place.place_id)

控制台输出:

代码语言:javascript
运行
复制
C:\Users\csjeemah\PycharmProjects\googleplaces\venv\Scripts\python.exe C:/Users/csjeemah/PycharmProjects/googleplaces/googleplaceID.py
777 Brockton Ave
ChIJmf-3TW6b5IkR1rx0eohvqPQ
30 Memorial Dr
ChIJXa_KpmGD5IkRYtpt2IsXmqg
Traceback (most recent call last):
  File "C:/Users/csjeemah/PycharmProjects/googleplaces/googleplaceID.py", line 27, in <module>
    query_result = google_places.text_search(
  File "C:\Users\csjeemah\PycharmProjects\googleplaces\venv\lib\site-packages\googleplaces\__init__.py", line 353, in text_search
    _validate_response(url, places_response)
  File "C:\Users\csjeemah\PycharmProjects\googleplaces\venv\lib\site-packages\googleplaces\__init__.py", line 175, in _validate_response
    raise GooglePlacesError(error_detail)
googleplaces.GooglePlacesError: Request to URL https://maps.googleapis.com/maps/api/place/textsearch/json?query=250+Hartford+Avenue%2C+Bellingham+MA+2019&radius=3200&language=en&key=mykey&sensor=false failed with response code: OVER_QUERY_LIMIT

在上面的控制台屏幕截图中,它返回前两个地址的结果,然后是错误occurs.Now --我理解这个错误的原因是,我可以发出的请求数量受到限制,但正如您从上面的图像中看到的:

  1. 只有9个地址。

  1. 如果我缩短几个地址,如下面所强调的:

它现在在失败之前检索更多的地址:

代码语言:javascript
运行
复制
C:\Users\csjeemah\PycharmProjects\googleplaces\venv\Scripts\python.exe C:/Users/csjeemah/PycharmProjects/googleplaces/googleplaceID.py
777 Brockton Ave
ChIJmf-3TW6b5IkR1rx0eohvqPQ
30 Memorial Dr
ChIJt_pwFGsUc2sR-ve6pnT9DlA
30 Memorial Dr
ChIJJatf08pZIWsRr2u-ppt2CyI
250 Hartford Ave
ChIJk567q-Jx5IkRGxbCzkmYU7A
Traceback (most recent call last):
  File "C:/Users/csjeemah/PycharmProjects/googleplaces/googleplaceID.py", line 27, in <module>
    query_result = google_places.text_search(
  File "C:\Users\csjeemah\PycharmProjects\googleplaces\venv\lib\site-packages\googleplaces\__init__.py", line 353, in text_search
    _validate_response(url, places_response)
  File "C:\Users\csjeemah\PycharmProjects\googleplaces\venv\lib\site-packages\googleplaces\__init__.py", line 175, in _validate_response
    raise GooglePlacesError(error_detail)
googleplaces.GooglePlacesError: Request to URL https://maps.googleapis.com/maps/api/place/textsearch/json?query=700+Oak+Street&radius=3200&language=en&key=mykey&sensor=false failed with response code: OVER_QUERY_LIMIT

我还试着在每次查询之后添加几秒钟的睡眠,但是它失败了,有人能告诉我问题出在哪里吗?

EN

回答 2

Stack Overflow用户

发布于 2020-01-23 04:04:09

图像中的错误json清楚地指出,您已经超出了places的每日请求配额。

如果您希望继续,您需要将您的GCP项目与计费帐户相关联。

票数 0
EN

Stack Overflow用户

发布于 2020-01-23 07:40:23

直接来自文档Google平台Web服务的使用限制

您可以通过以下方式超过Google平台web服务的使用限制:

  • 每天发送的请求太多了。
  • 发送请求的速度太快,即每秒发送的请求太多。
  • 发送请求太快太长时间或其他滥用web服务。
  • 超过其他使用限制,例如海拔API中的每个请求点数。

在收到状态代码OVER_QUERY_LIMIT的响应后,应用程序应该确定已经超过了哪个使用限制。这可以通过暂停2秒并重新发送相同的请求来完成。如果状态代码仍然是OVER_QUERY_LIMIT,则应用程序每天发送的请求太多。否则,应用程序每秒发送的请求太多。

代码语言:javascript
运行
复制
url = "MAPS_API_WEBSERVICE_URL"
attempts = 0
success = False

while success != True and attempts < 3:
  raw_result = urllib.urlopen(url).read()
  attempts += 1
  # The GetStatus function parses the answer and returns the status code
  # This function is out of the scope of this example (you can use a SDK).
  status = GetStatus(raw_result)
  if status == "OVER_QUERY_LIMIT":
    time.sleep(2)
    # retry
    continue
  success = True

if attempts == 3:
  # send an alert as this means that the daily limit has been reached
  print "Daily limit has been reached"
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59871191

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档