exchangelib: folder:UnreadCount not supported on Exchange 2010?
Hi ecederstrand,
I’m trying to access the calendar of my account. I was able to get the calendar items through account.root,get_folder_by_name(‘Calendar’). But when I tried to directly pull the calendar view to get availability at a certain time. It returned error as below. Wondering if you know what is the reason for that. Really appreciate it!
Thank you so much!
Traceback (most recent call last)
C:\ProgramData\Anaconda\lib\site-packages\cached_property.py in __get__(self, obj, cls)
49 # check if the value was computed before the lock was acquired
---> 50 return obj_dict[name]
51 except KeyError:
KeyError: 'calendar'
During handling of the above exception, another exception occurred:
ErrorInvalidPropertyRequest Traceback (most recent call last)
<ipython-input-45-8bf1ed0c630e> in <module>()
2 start_dt = ts.localize(EWSDateTime(2018, 3,1,14,0)),
3 end_dt = ts.localize(EWSDateTime(2018, 3, 1,14,30))
----> 4 account.calendar.view(start=start_dt, end=end_dt)
C:\ProgramData\Anaconda\lib\site-packages\cached_property.py in __get__(self, obj, cls)
51 except KeyError:
52 # if not, do the calculation and release the lock
---> 53 return obj_dict.setdefault(name, self.func(obj))
54
55
C:\ProgramData\Anaconda\lib\site-packages\exchangelib\account.py in calendar(self)
149 # Attempt not to return one of those. An account may not always have a calendar called "Calendar", but a
150 # Calendar folder with a localized name instead. Return that, if it's available.
--> 151 return self.root.get_default_folder(Calendar)
152
153 @threaded_cached_property
C:\ProgramData\Anaconda\lib\site-packages\exchangelib\folders.py in get_default_folder(self, folder_cls)
735 # Get the default folder
736 log.debug('Testing default %s folder with GetFolder', folder_cls)
--> 737 f = folder_cls.get_distinguished(account=self.account)
738 return self._folders_map.get(f.folder_id, f) # Use cached instance if available
739 except ErrorAccessDenied:
C:\ProgramData\Anaconda\lib\site-packages\exchangelib\folders.py in get_distinguished(cls, account)
619 def get_distinguished(cls, account):
620 assert cls.DISTINGUISHED_FOLDER_ID
--> 621 folders = list(cls.get_folders(account=account, ids=[cls(account=account, name=cls.DISTINGUISHED_FOLDER_ID)]))
622 if not folders:
623 raise ErrorFolderNotFound('Could not find distinguished folder %s' % cls.DISTINGUISHED_FOLDER_ID)
C:\ProgramData\Anaconda\lib\site-packages\exchangelib\folders.py in get_folders(cls, account, ids, additional_fields)
610 folders=ids,
611 additional_fields=additional_fields,
--> 612 shape=IdOnly
613 ):
614 if isinstance(elem, Exception):
C:\ProgramData\Anaconda\lib\site-packages\exchangelib\services.py in _get_elements_in_response(self, response)
281 for msg in response:
282 assert isinstance(msg, ElementType)
--> 283 container_or_exc = self._get_element_container(message=msg, name=self.element_container_name)
284 if isinstance(container_or_exc, ElementType):
285 for c in self._get_elements_in_container(container=container_or_exc):
C:\ProgramData\Anaconda\lib\site-packages\exchangelib\services.py in _get_element_container(self, message, name)
254 # rspclass == 'Error', or 'Success' and not 'NoError'
255 try:
--> 256 self._raise_errors(code=response_code, text=msg_text, msg_xml=msg_xml)
257 except self.ERRORS_TO_CATCH_IN_RESPONSE as e:
258 return e
C:\ProgramData\Anaconda\lib\site-packages\exchangelib\services.py in _raise_errors(cls, code, text, msg_xml)
271 try:
272 # Raise the error corresponding to the ResponseCode
--> 273 raise vars(errors)[code](text)
274 except KeyError:
275 # Should not happen
ErrorInvalidPropertyRequest: Property is not valid for this object type. (field: <ns0:FieldURI xmlns:ns0="http://schemas.microsoft.com/exchange/services/2006/types" FieldURI="folder:UnreadCount" />)
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 19 (10 by maintainers)
Sorry! I tried to shorten the workaround but introduced an embarrassing bug along the way. Never change a list while iterating over it! .pop() changes the list so the index in the next iteration no longer points to the right item.
I don’t think exchangelib should handle this automatically until we have a much better idea about what causes this.
For now, I would suggest handling this in your client code. Connect to the server and read the
unread_countattribute for an arbitrary folder. If that fails, then apply the workaround mentioned in https://github.com/ecederstrand/exchangelib/issues/352#issuecomment-370706598 and try again.