3
votes

I am using Google Calendar API and quick start code for Python. The quick start code works, however when I try to retrieve calendar event attendees, I get a "key error". The original code for retrieving calendar events is

for event in events:
    start = event['start'].get('dateTime', event['start'].get('date'))
    print(start, event['summary'])

I added attendees like this:

for event in events:
    start = event['start'].get('dateTime', event['start'].get('date'))
    print(start, event['summary'],event['attendees'])

'attendees' is a valid term to use as it is listed in the Python API reference.

Any thoughts why retrieving attendees doesn't work?

1

1 Answers

2
votes

Not every event does have attendees. so If an event doesn't have any attendees, the response object won't have an attendees attribute. you can use

print(start, event['summary'], event.get('attendees', []))

instead of

print(start, event['summary'], event['attendees'])

and it will set an empty list when no attendees exists