首页 > 解决方案 > “配额组'ReadGroup'的配额超出并限制'每100秒每个用户的读取请求'服务google api

问题描述

我尝试计算请求 api 和时间的代码

a =0
count_time = 0
while True:
    start = time.time()
    if (sheet.cell(22,9).value) == "#N/A":
        a = a+1
        print("google read request: ",a)
        time.sleep(1)


    if (sheet.cell(22,9).value) == "#N/A":
        a = a+1
        print("google read request: ",a)
        time.sleep(1)

    if (sheet.cell(22,9).value) == "#N/A":
        a = a+1
        print("google read request: ",a)
        time.sleep(1)


    success_loop_time = time.time()-start
    count_time = count_time + success_loop_time
    print("Time: ", round(count_time) , "sec")

最后结果:

Time:  103 sec

google read request:  77

然后这个错误显示


    raise APIError(response)
gspread.exceptions.APIError: {
  "error": {
    "code": 429,
    "message": "Quota exceeded for quota group 'ReadGroup' and limit 'Read requests per user per 100 seconds' of service 'sheets.googleapis.com' for consumer 'project_number:1001198111824'.",        
    "status": "RESOURCE_EXHAUSTED",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.Help",
        "links": [
          {
            "description": "Google developer console API key",
            "url": "https://console.developers.google.com/project/1001198111824/apiui/credential"
          }
        ]
      }
    ]
  }
}

但我每 100 秒的限制配额读取请求是 500 在此处输入图像描述

你能帮我修复五天前我仍然运行这段代码没有错误

对不起我的英语不好

标签: python-3.xgoogle-sheetsgoogle-api

解决方案


请注意,除了每个项目每 100 秒 500 个请求的限制外,每个用户还有每 100 秒 100 个请求的限制,请参见此处

仅此一项并不能解释为什么您达到了每 103 秒 77 个读取请求的配额,

但请记住:

  • 如果您不是管理员,您的管理员可能会将您的配额限制为每秒少于 100 个请求
  • 配额不仅适用于读取请求,还包括您可能同时拥有的其他请求(例如写入),以及在后台运行的其他代码的请求。

推荐阅读