python-o365
python-o365 copied to clipboard
Calendar - Reading shared events, specifically a private event
I have come across a problem when using a shared maibox calendar.
it was working fine, then the user added a 'private event'
The private event only emails very limited information (generally date and time only) to other users.
This then causes an issue when trying to read 'body' as it does not exist in the json
File "/home/pi/dashdisplay/app_calendar.py", line 214, in process
for o365_event in o365_mycalendarEvents:
File "/usr/local/lib/python3.7/dist-packages/O365/calendar.py", line 1765, in <genexpr>
for event in data.get('value', []))
File "/usr/local/lib/python3.7/dist-packages/O365/calendar.py", line 847, in __init__
self.__body = body.get(cc('content'), '')
AttributeError: 'NoneType' object has no attribute 'get'
I'm not sure which other 'standard' loaded values are missing from the json, i have not got past this yet.
The previous line is:
body = cloud_data.get(cc('body'), {})
So if there's no body in the json, then body should be an empty dict.
I don't understand right now how body
ends up being None...
Nontheless maybe we should protect like this:
body = cloud_data.get(cc('body'), {})
body = body or {} # <= protect agains body being None
self.__body = body.get(cc('content'), '')
self.body_type = body.get(cc('contentType'), 'HTML') # default to HTML for new messages
looks like a good fix I have no idea what other 'standard' fields might be returned invalid/different
I’ll commit soon this fix