Remove / Add / Update attachments on calendar events (is this functilality broken?)
Hi
Just want to thank you for this great library. Has helped me a lot working with the microsoft O365 world. However I found myself struggle with the calendar function.
I have integrated two calendar systems. I use a small attachment in the calendar event to store the relation between the calendar systems. However I came across a use case where I had to remove an attachment. I ran the following code:
event = calendar.get_event(id_of_event) SOME CHANGE TO THE EVENT event.attachments.download_attachments() event.attachments.remove( f"agreed_name.json") event.save()
The attachment is not removed from the event.
Then I read https://github.com/O365/python-o365/issues/223 and figured out that there is some sort of workaround for uploading event attachments
event = calendar.get_event(id_of_event) SOME CHANGE TO THE EVENT event.save() event.attachments.download_attachments() event.attachments.remove( f"agreed_name.json") event.attachments._update_attachments_to_cloud() # A workaround I found in github issues
Unfortunately I received a ValueError:
File "/Users/<project>/venv/lib/python3.8/site-packages/O365/utils/attachment.py", line 476, in _update_attachments_to_cloud
url = self.build_url(self._endpoints.get('attachment').format(
AttributeError: 'NoneType' object has no attribute 'format'
I have tried a bit back and fourth to override the _endpoints dictionary with endpoint templates, but no luck so far.
Uploading attachments definitely works. I should see why removing them does not...
Probably a bug
In O365 there is no endpoint url added for adding attachment in event , you can customise the Event class for new endpoint url 'event_attachment': '/events/{id}/attachments',
data = self.to_api_data(restrict_keys=self._track_changes) _attachments = data.get('attachments', None) if _attachments: url = self.build_url( self._endpoints.get('event_attachment').format(id=self.object_id)) method = self.con.post for data in _attachments: try: response = method(url, data=data) except: continue Sorry I am not able push the changes Pushing to https://github.com/O365/python-o365.git remote: Permission to O365/python-o365.git denied to ganeshcmohan.
@ganeshcmohan You need to use Pull Requests...
@janscas Opened a pull request that hopefully tackles this problem as well