I am using google calendar api with python. I have created a service account, and am using the private key to connect to the calendar api from my server.
Everything was working fine.
Yesterday I started getting the error:
{
"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "dailyLimitExceededUnreg",
"message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.",
"extendedHelp": "https://code.google.com/apis/console"
}
],
"code": 403,
"message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup."
}
}
When I log into the console my limits are:
Daily quotas reset at midnight Pacific Time (PT).
Queries
requests/day 114 of 1,000,000
requests/100seconds/user 500
The console correctly shows me that I am hitting 4XX errors and each hit increments the error count, but I am not sure how to fix this
Does anyone have some idea where I could start looking?
Below my code I use to connect
with open(os.path.dirname(os.path.abspath(__file__)) + "/KeyName.p12") as f:
private_key = f.read()
credentials = SignedJwtAssertionCredentials(client_email, private_key,
scope=['https://www.googleapis.com/auth/calendar', 'https://www.googleapis.com/auth/calendar.readonly'])
http = Http()
credentials.authorize(http)
service = build(serviceName='calendar', version='v3', http=http)
today_beginning = datetime.combine(date.today(), time())
today_end = today_beginning + timedelta(1, 0) - timedelta(0, 1)
now = datetime.now().isoformat()
timeMin = today_beginning.isoformat() + 'Z'
timeMax = today_end.isoformat() + 'Z'
# events
events = service.events().list(calendarId=calendar_id, timeMin=timeMin, timeMax=timeMax).execute()
At this stage it break with
raise HttpError(resp, content, uri=self.uri) googleapiclient.errors.HttpError: https://www.googleapis.com/calendar/v3/calendars/.../hidden/parts/.. returned "Not Found">
Below is an image showing my requests over the last 30 days, you'll see where to 200 drop and the 4xx begin
UPDATE: I have made some changes with limited success
I changed the code to the following
scopes = ['https://www.googleapis.com/auth/calendar.readonly']
# p12 keyfile
# keyfile = os.path.dirname(os.path.abspath(__file__)) + "/" + p12_key
# credentials = ServiceAccountCredentials.from_p12_keyfile(client_email, keyfile, 'notasecret', scopes)
# json keyfile
keyfile = os.path.dirname(os.path.abspath(__file__)) + "/" + json_key
credentials = ServiceAccountCredentials.from_json_keyfile_name(keyfile, scopes)
http_auth = credentials.authorize(Http())
service = build(serviceName='calendar', version='v3', http=http_auth)
today_beginning = datetime.combine(date.today(), time())
today_end = today_beginning + timedelta(1, 0) - timedelta(0, 1)
now = datetime.now().isoformat()
timeMin = today_beginning.isoformat() + 'Z'
timeMax = today_end.isoformat() + 'Z'
# events
events = service.events().list(calendarId=calendar_id, timeMin=timeMin, timeMax=timeMax).execute()
This code reflects the latest changes from the documentation
I tried to authenticate by using json & a p12 cert
The error still persisted. I created another service account, with new credentials, json+p12 and the error still persisted. I created new calendars, the error persisted.
I then created a service account on another google account that I have, recreated the calendars, and created new credentials for this service account. That made it work again.
This makes me think that there is something going on with the accounts?
The account where the error occurs is a paid for google apps for business account. I will log a ticket with that account and report back