0
votes

in using the google calendar api (with python), I've been able to get back the variables I want, so I can export events into a text file. However, one variable (the location) is triggering an error and I'm not sure why.

This is straight from google's start code, with additions by me for the variables I want:

   if not events:
    print('No upcoming events found.')
for event in events:
    start = event['start'].get('dateTime', event['start'].get('date'))
#    print(start, event['summary'], event['description'], event['location'],  event['iCalUID'])
    print(start, event['summary'], event['location'], event['iCalUID'])

It prints a list of upcoming appointments including the location, but it stops and throws this error at me

Traceback (most recent call last):
  File "tryingnewstuff.py", line 39, in <module>
    print(start, event['summary'], event['description'], event['location'],  event['iCalUID'])
KeyError: 'location'

Is this a problem with credentials/json? Am I using an old version of google calendar api? How do I check that? My json file says {"_module": "oauth2client.client", "scopes": ["https://www.googleapis.com/auth/calendar.readonly"], "

2
Thank you for replying. In your question, I thought that you want to know about the reason of KeyError: 'location'. But from your replying, it seems that my understanding was not correct. So I have to remove my answer. I deeply apologize for my poor skill. - Tanaike
Then, from It is getting the summary and even the location just fine, in your situation, even when the property of location is included in the object of the element, the error occurs. If my understanding is correct, can you provide the whole script and values for completely replicating your issue? By this, I would like to confirm it. Of course, please remove your personal information. If you can cooperate to resolve your issue, I'm glad. - Tanaike

2 Answers

0
votes

If you want change setting on "scope" variable. maybe you can delete credential file, And add scope array, last rerun your .py file

0
votes

It ended up being that I just needed to upgrade to the latest google API. I didn't end up using it anyway. But thank you for the responses!