1

I'm trying to read a fairly large calendar using almost unchanged code from the official documentation.

from exchangelib import DELEGATE, Account, Credentials, CalendarItem, close_connections
from exchangelib.protocol import BaseProtocol
credentials = Credentials(
    username='username',  
    password='password'
)
account = Account(
    primary_smtp_address='address', 
    credentials=credentials, 
    autodiscover=True,
    access_type=DELEGATE)
    
a = account

for calendar_item in a.calendar.all():
    print('--------------------------')
    print(calendar_item.organizer, calendar_item.start)

account.protocol.close()

At the same time, nothing happens at all for the first minute of the script. Then several hundred lines of output are output that I need. After that, the script is stopped by a timeout with the following error: raise self._get_exception(code=response_code, text=msg_text, msg_xml=msg_xml) exchangelib.errors.ErrorTimeoutExpired: The request timed out.

Can I somehow increase the timeout or change the request so that it works faster?

1 Answers1

0

The script isn't idling the first minute. If you enable debug logging, you'll most likely see that it's autodiscovery that's taking a long time. You can cache autodiscover results and use them the next time you run the script, if you want to improve startup time.

There are at least three approaches to fixing your issue (they can even be combined):

  1. Increate the timeout. Set eg. BaseProtocol.TIMEOUT = 600
  2. Decreate the amount of data that is fetched. Instead of a.calendar.all(), do a.calendar.all().only('organizer', 'start')
  3. Configure a retry policy to have exchangelib try again if it hits a timeout error.
Erik Cederstrand
  • 9,643
  • 8
  • 39
  • 63