My application creates and deletes Google Calendar events on behalf of users. Each user authorizes through the OAuth portal and that user's access_token is used to access the API, rather than a service account.
I was having issues with various rate-limit errors, and so I started to batch requests. But despite batching requests, many of the requests within the batch fail. It is only me testing this locally -- there are no other users on the service.
For example, you can see below that several of the deletes in the batch request failed (numbers 2, 6, 7, 8, etc.). This batch request with ~a dozen delete requests was the only thing sent in the previous several minutes, and there had been probably 6 batch requests in the previous hour (many with the same issue).
If I then fired off another batch request immediately after, I would see the same pattern: several of the sub-requests succeeding and others failing. This leads me to believe that I haven't gone over any sort of global / day-based limit, but rather that there's something broken in the batch request itself.
[2020-08-03 13:55:03,101: WARNING/ForkPoolWorker-1] Error with batch delete request "1": <HttpError 403 when requesting https://www.googleapis.com/calendar/v3/calendars/X.com_X%40group.calendar.google.com/events/X? returned "Rate Limit Exceeded">
[2020-08-03 13:55:03,102: WARNING/ForkPoolWorker-1] Error with batch delete request "3": <HttpError 403 when requesting https://www.googleapis.com/calendar/v3/calendars/X.com_X%40group.calendar.google.com/events/X? returned "Rate Limit Exceeded">
[2020-08-03 13:55:03,102: WARNING/ForkPoolWorker-1] Error with batch delete request "4": <HttpError 403 when requesting https://www.googleapis.com/calendar/v3/calendars/X.com_X%40group.calendar.google.com/events/X? returned "Rate Limit Exceeded">
[2020-08-03 13:55:03,103: WARNING/ForkPoolWorker-1] Error with batch delete request "5": <HttpError 403 when requesting https://www.googleapis.com/calendar/v3/calendars/X.com_X%40group.calendar.google.com/events/X? returned "Rate Limit Exceeded">
[2020-08-03 13:55:03,103: WARNING/ForkPoolWorker-1] Error with batch delete request "6": <HttpError 403 when requesting https://www.googleapis.com/calendar/v3/calendars/X.com_X%40group.calendar.google.com/events/X? returned "Rate Limit Exceeded">
[2020-08-03 13:55:03,103: WARNING/ForkPoolWorker-1] Error with batch delete request "9": <HttpError 403 when requesting https://www.googleapis.com/calendar/v3/calendars/X.com_X%40group.calendar.google.com/events/X? returned "Rate Limit Exceeded">
[2020-08-03 13:55:03,103: WARNING/ForkPoolWorker-1] Error with batch delete request "10": <HttpError 403 when requesting https://www.googleapis.com/calendar/v3/calendars/X.com_X%40group.calendar.google.com/events/X? returned "Rate Limit Exceeded">
(the Xs are my redaction of personal info)
To the extent it's helpful, here's the very basic code causing this:
batch = c.new_batch_http_request(callback=batch_delete_callback)
for event in events:
if event is not None:
r = c.events().delete(calendarId=gcal_id, eventId=event)
batch.add(r)
batch.execute()
And the callback:
def batch_delete_callback(request_id, response, exception):
if exception is not None:
print('Error with batch delete request "{0}": {1}'.format(
request_id, exception))
What am I doing wrong here and how can I best handle or avoid these 403s from Google?
Update
I just tried to minimally test this, to get the immediate failure case. I ran a batch request that added 12 events to my calendar, and then ran a batch request that attempted to delete those same 12 events roughly 15 seconds later. So just 2 batch requests with 12 sub-requests in each. And this is after no action whatsoever for 20 hours since I last tried.
And of the 12 delete requests, 8 of them failed. So I had 12 create requests succeed, and then 8/12 delete requests returned a 403 Rate Limit Exceeded
As noted in my comments below, my console shows quotas of 1,000,000 queries per day and 100,000,000 queries per 100 seconds per user. So I just can't tell what limit I'm hitting.