exchangelib: The request timed out

I receive following error. It has been working for a while and now it suddenly has this error again. I am sifting through about 1000 emails every time. So it works “mostly” . I also have increased the TIMEOUT value. I run the same emails again and again in the same folder with :

for item in folder.all():

Python 2.7 64-bit Windows Server 2016 Standard

`Traceback (most recent call last):

File “<ipython-input-23-0563b9a66ad5>”, line 1, in <module> runfile(‘C:/scripts/temp7.py’, wdir=‘C:/scripts’)

File “C:\ProgramData\Anaconda2\lib\site-packages\spyder\utils\site\sitecustomize.py”, line 710, in runfile execfile(filename, namespace)

File “C:\ProgramData\Anaconda2\lib\site-packages\spyder\utils\site\sitecustomize.py”, line 86, in execfile exec(compile(scripttext, filename, ‘exec’), glob, loc)

File “C:/scripts/temp7.py”, line 148, in <module> for item in incidents.all():

File “C:\ProgramData\Anaconda2\lib\site-packages\exchangelib\queryset.py”, line 311, in iter for val in self._format_items(items=self._query(), return_format=self.return_format):

File “C:\ProgramData\Anaconda2\lib\site-packages\exchangelib\queryset.py”, line 390, in _as_items for i in iterable:

File “C:\ProgramData\Anaconda2\lib\site-packages\exchangelib\account.py”, line 629, in fetch shape=IdOnly,

File “C:\ProgramData\Anaconda2\lib\site-packages\exchangelib\services.py”, line 608, in _pool_requests for elem in elems:

File “C:\ProgramData\Anaconda2\lib\site-packages\exchangelib\services.py”, line 330, in _get_elements_in_response container_or_exc = self._get_element_container(message=msg, name=self.element_container_name)

File “C:\ProgramData\Anaconda2\lib\site-packages\exchangelib\services.py”, line 303, in _get_element_container raise self._get_exception(code=response_code, text=msg_text, msg_xml=msg_xml)

ErrorTimeoutExpired: The request timed out.

`

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 16 (8 by maintainers)

Most upvoted comments

Ok. You may be able to reduce the pressure of your query by limiting the fields you fetch from the server to the ones you actually need. For example, mime_content may be huge if your emails contain attachments.

for item in folder.all().only('subject', 'datetime_received', 'sender'):
    # Do something

Ok. I mistook this for an exception from the requests package. Actually, it’s an error from the server telling you that you are being throttled, or that the server is hard at work. See https://docs.microsoft.com/en-us/exchange/client-developer/exchange-web-services/handling-synchronization-related-errors-in-ews-in-exchange and https://docs.microsoft.com/en-us/exchange/client-developer/web-service-reference/responsecode

Try either lowering the connection count (BaseProtocol.SESSION_POOLSIZE) or the page size of your batch operations (QuerySet.page_size).

It seems from the stack trace that your query is unnecessarily expensive. If you just want to count the number of items in a folder, you can use the some_folder.total_count or some_folder.unread_count attributes. If you want to get the item count of a filtered list of items, do some_folder.filter(subject='foo').count() .

Iterating over .all() consumes a generator, so items will be fetched from the server and returned according to the defined page size (currently 100 by default).