2
votes

My code that i try to count request api and time

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")

Last result :

Time:  103 sec

google read request:  77

then this error show


    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"
          }
        ]
      }
    ]
  }
}

but my limit quota read request per 100 sec is 500 enter image description here

could you help me to fix five days ago i still run this code have no error

sorry about my english language is not well

1

1 Answers

1
votes

Be aware that apart from the limit of 500 requests per 100 seconds per project, there is also the limit of 100 requests per 100 seconds per user, see here.

This alone does not explain why you hit the quota with 77 read requests per 103 s,

but keep also in mind:

  • If you are not admin, your admin might restrict your quota to less than 100 requests per s
  • The quota does not apply to read requests only, but it also includes other requests you might have simulatenously (e.g. writing), and also requests of other codes running in the background.