O365 / python-o365

A simple python library to interact with Microsoft Graph and Office 365 API
Apache License 2.0
1.68k stars 424 forks source link

Calendar - Reading shared events, specifically a private event #697

Open topcats opened 3 years ago

topcats commented 3 years ago

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.

alejcas commented 3 years ago

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
topcats commented 3 years ago

looks like a good fix I have no idea what other 'standard' fields might be returned invalid/different

alejcas commented 3 years ago

I’ll commit soon this fix