exchangelib icon indicating copy to clipboard operation
exchangelib copied to clipboard

ErrorInvalidSchemaVersionForMailboxVersion with exchangelib v5.2.1 and Exchange server version 15.2.1544.4

Open oKenneth opened this issue 10 months ago • 25 comments

Describe the bug When trying to access Exchange folders via account.msg_folder_root.tree() we run into this error message: exchangelib.errors.ErrorInvalidSchemaVersionForMailboxVersion: Tried versions ('Exchange2016', 'Exchange2015_SP1', 'Exchange2015', 'Exchange2013_SP1', 'Exchange2013', 'Exchange2010_SP2', 'Exchange2010_SP1', 'Exchange2010', 'Exchange2007_SP1', 'Exchange2007') but all were invalid

This worked with exchangelib v4.9.0 and now fails after updating to v5.2.1. The Exchange server version comes back as "V2017_07_11" (15.2.1544.4). I also include the ServerVersionInfo response header in the log outputs below.

The GetFolder call in folders/collections.py runs through when requesting folders DistinguishedFolderId Id="root" and DistinguishedFolderId Id="msgfolderroot". But then on the third call for the children of "msgfolderroot" it crashes with the above error, after retrieving a faulty xml response with an ErrorInvalidRequest.

As build 15.2.1544.4 corresponds to a 2019 Exchange server version and the api version string for Exchange 2019 was changed from "Exchange2019" to "Exchange2016" between exchangelib version v4.9.0 and v5.2.1, could that change have caused this issue?

To Reproduce You'll need an Exchange server running on version 15.2.1544.4. Then this code should produce the error:

#!/usr/bin/env python3
import sys
import logging
from exchangelib import (
    Account,
    Configuration,
    Credentials,
    DELEGATE,
    EWSDateTime,
    EWSTimeZone,
    Folder,
    Identity,
    IMPERSONATION,
)
logging.basicConfig(level=logging.DEBUG)

server, username, password = sys.argv[1:]

account = Account(
    primary_smtp_address=username,
    autodiscover=False,
    access_type=DELEGATE,
    config=Configuration(
        server=server,
        credentials=Credentials(username, password)
    ),
    default_timezone=EWSTimeZone("Europe/Berlin"),
)

print(account.msg_folder_root.tree())

Log output Traceback:

Traceback (most recent call last):
  File "/opt/omd/sites/prod/test.py", line 32, in <module>
    print(account.msg_folder_root.tree())
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/omd/sites/prod/lib/python3.12/site-packages/exchangelib/folders/base.py", line 199, in tree
    children = list(self.children)
               ^^^^^^^^^^^^^^^^^^^
  File "/omd/sites/prod/lib/python3.12/site-packages/exchangelib/folders/collections.py", line 46, in __len__
    return len(self.folders)
               ^^^^^^^^^^^^
  File "/omd/sites/prod/lib/python3.12/site-packages/cached_property.py", line 77, in __get__
    return obj_dict.setdefault(name, self.func(obj))
                                     ^^^^^^^^^^^^^^
  File "/omd/sites/prod/lib/python3.12/site-packages/exchangelib/folders/collections.py", line 43, in folders
    return tuple(self._folders)
           ^^^^^^^^^^^^^^^^^^^^
  File "/omd/sites/prod/lib/python3.12/site-packages/exchangelib/folders/roots.py", line 98, in get_children
    for f in self._folders_map.values():
             ^^^^^^^^^^^^^^^^^
  File "/omd/sites/prod/lib/python3.12/site-packages/exchangelib/folders/roots.py", line 174, in _folders_map
    for f in FolderCollection(account=self.account, folders=distinguished_folders).resolve():
  File "/omd/sites/prod/lib/python3.12/site-packages/exchangelib/folders/collections.py", line 335, in resolve
    yield from self.__class__(account=self.account, folders=resolveable_folders).get_folders(
  File "/omd/sites/prod/lib/python3.12/site-packages/exchangelib/folders/collections.py", line 403, in get_folders
    yield from GetFolder(account=self.account).call(
  File "/omd/sites/prod/lib/python3.12/site-packages/exchangelib/services/get_folder.py", line 51, in _elems_to_objs
    for folder, elem in zip(self.folders, elems):
  File "/omd/sites/prod/lib/python3.12/site-packages/exchangelib/services/common.py", line 287, in _chunked_get_elements
    yield from self._get_elements(payload=payload_func(chunk, **kwargs))
  File "/omd/sites/prod/lib/python3.12/site-packages/exchangelib/services/common.py", line 308, in _get_elements
    yield from self._response_generator(payload=payload)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/omd/sites/prod/lib/python3.12/site-packages/exchangelib/services/common.py", line 271, in _response_generator
    response = self._get_response_xml(payload=payload)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/omd/sites/prod/lib/python3.12/site-packages/exchangelib/services/common.py", line 436, in _get_response_xml
    raise self.NO_VALID_SERVER_VERSIONS(f"Tried versions {self._api_versions_to_try()} but all were invalid")
exchangelib.errors.ErrorInvalidSchemaVersionForMailboxVersion: Tried versions ('Exchange2016', 'Exchange2015_SP1', 'Exchange2015', 'Exchange2013_SP1', 'Exchange2013', 'Exchange2010_SP2', 'Exchange2010_SP1', 'Exchange2010', 'Exchange2007_SP1', 'Exchange2007') but all were invalid
DEBUG:exchangelib.protocol:Server <server_name>: Closing sessions

ServerVersionInfo in response xml:

Response XML: b'<?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Header><h:ServerVersionInfo MajorVersion="15" MinorVersion="2" MajorBuildNumber="1544" MinorBuildNumber="4" Version="V2017_07_11"

Faulty response xml:

Response XML: b'<?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><s:Fault><faultcode xmlns:a="http://schemas.microsoft.com/exchange/services/2006/types">a:ErrorInvalidRequest</faultcode><faultstring xml:lang="de-DE">The request is invalid.</faultstring><detail><e:ResponseCode xmlns:e="http://schemas.microsoft.com/exchange/services/2006/errors">ErrorInvalidRequest</e:ResponseCode><e:Message xmlns:e="http://schemas.microsoft.com/exchange/services/2006/errors">The request is invalid.</e:Message></detail></s:Fault></s:Body></s:Envelope>'

Additional context Python version: 3.12.1 exchangelib version: 5.2.1 Exchange server version: "V2017_07_11" (15.2.1544.4)

oKenneth avatar Apr 23 '24 08:04 oKenneth

Thanks for the report!

We made the change in API version from Exchange2019 to Exchange2016 in https://github.com/ecederstrand/exchangelib/issues/1210.

Does switching back to exchangelib v4.9.0 actually work? If so, you can test this workaround in v5.2.1:

import exchangelib.version
tmp = list(exchangelib.version.VERSIONS)
tmp[1] = (exchangelib.version.EXCHANGE_2019, "Exchange2019", "Microsoft Exchange Server 2019")
exchangelib.version.VERSIONS = tuple(tmp)

ecederstrand avatar Apr 23 '24 08:04 ecederstrand

Thanks for your quick response! Yes, this still works on exchangelib v4.9.0. Changing the api version string back to "Exchange2019" actually does not fix the error. We still get the faultcode xml response for each of the tried api versions. Do you have an idea what else might cause this?

I noticed that for the failing request, the response headers do not include the fields 'Content-Encoding': 'gzip', 'Vary': 'Accept-Encoding', while for the successful requests ("root" and "msgfolderroot") these are included. Is that expected?

oKenneth avatar Apr 23 '24 09:04 oKenneth

In that case, your best bet is to run a successful and a non-successful connection attempt and compare the XML requests and responses.

You can also try hardcoding the version number in the connection:

from exchangelib.version import EXCHANGE_2019, Version

account = Account(
    ...
    config=Configuration(
        version = Version(build=EXCHANGE_2019),
        ...
    ),
)

to see if that will get you past the error.

ecederstrand avatar Apr 23 '24 10:04 ecederstrand

I am getting the same error with both exchangelib 5.2.1 and 5.3.0, and it still occurs if I use a Configuration object with the Exchange version hardcoded. Downgrading to exchangelib 5.2.0 makes the error go away.

laurachan avatar Apr 27 '24 00:04 laurachan

To find out what's wrong you'll need to compare the XML requests and responses of a working and non-working version. Enable debug logging and post the request and response where the two versions differ.

ecederstrand avatar Apr 27 '24 10:04 ecederstrand

Hardcoding the version did not solve the problem on the v5.2.1 for us either.

I looked into the requests and responses for both v4.9.0 and v5.2.1. As mentioned in the original issue post, we have three calls to GetFolder - 1) requesting "root", 2) requesting "msgfolderroot", and 3) requesting the children of "msgfolderroot".

  • for 1) the XML response on v5.2.1 holds these additional fields compared to v4.9.0:
<t:DistinguishedFolderId>root</t:DistinguishedFolderId>
<t:PermissionSet>
    <t:Permissions>
        <t:Permission>
            <t:UserId>
                <t:DistinguishedUser>Default</t:DistinguishedUser>
            </t:UserId>
            <t:CanCreateItems>false</t:CanCreateItems>
            <t:CanCreateSubFolders>false</t:CanCreateSubFolders>
            <t:IsFolderOwner>false</t:IsFolderOwner>
            <t:IsFolderVisible>false</t:IsFolderVisible>
            <t:IsFolderContact>false</t:IsFolderContact>
            <t:EditItems>None</t:EditItems>
            <t:DeleteItems>None</t:DeleteItems>
            <t:ReadItems>None</t:ReadItems>
            <t:PermissionLevel>None</t:PermissionLevel>
        </t:Permission>
        <t:Permission>
            <t:UserId>
                <t:DistinguishedUser>Anonymous</t:DistinguishedUser>
            </t:UserId>
            <t:CanCreateItems>false</t:CanCreateItems>
            <t:CanCreateSubFolders>false</t:CanCreateSubFolders>
            <t:IsFolderOwner>false</t:IsFolderOwner>
            <t:IsFolderVisible>false</t:IsFolderVisible>
            <t:IsFolderContact>false</t:IsFolderContact>
            <t:EditItems>None</t:EditItems>
            <t:DeleteItems>None</t:DeleteItems>
            <t:ReadItems>None</t:ReadItems>
            <t:PermissionLevel>None</t:PermissionLevel>
        </t:Permission>
    </t:Permissions>
</t:PermissionSet>

Note that on v4.9.0 api version "Exchange 2019" is tried first: DEBUG:exchangelib.services.common:Trying API version Exchange2019, yet comes back with a 500. This does not come up on v5.2.1 of course, as there's no api version with identifier "Exchange 2019".

  • for 2) the XML response on v5.2.1 only holds this additional filed compared to v4.9.0:
<t:DistinguishedFolderId>msgfolderroot</t:DistinguishedFolderId>
  • for 3) the XML request on v5.2.1 holds this additional filed compared to v4.9.0:
<t:FieldURI FieldURI="folder:DistinguishedFolderId"/>

and then a block like this for each of the 22 more folders that are found compared to v4.9.0:

<t:DistinguishedFolderId Id="allcategorizeditems">
    <t:Mailbox>
        <t:EmailAddress>[email protected]</t:EmailAddress>
        <t:RoutingType>SMTP</t:RoutingType>
        <t:MailboxType>Mailbox</t:MailboxType>
    </t:Mailbox>
</t:DistinguishedFolderId>

On v5.2.1 we get a faultcode response while on v4.9.0 the response holds the expected folder data.

oKenneth avatar Apr 29 '24 07:04 oKenneth

It looks like EWS doesn't like the GetFolder XML format of one or more of the child folders. Can you try out something like this?

from exchangelib.folders import FolderCollection, SingleFolderQuerySet

for f in FolderCollection(account=account, folders=[account.msg_folder_root]).find_folders():
    try:
        f = SingleFolderQuerySet(account=account, folder=f).resolve()
        print(f"GetFolder on folder {f.name} succeeded")
    except Exception as e:
        print(f"ERROR: GetFolder on folder {f} failed")

ecederstrand avatar Apr 29 '24 13:04 ecederstrand

Also, it would be great if you can post the full XML response containing the error message from the server when this happens.

ecederstrand avatar Apr 29 '24 13:04 ecederstrand

It looks like EWS doesn't like the GetFolder XML format of one or more of the child folders. Can you try out something like this?

from exchangelib.folders import FolderCollection, SingleFolderQuerySet

for f in FolderCollection(account=account, folders=[account.msg_folder_root]).find_folders():
    try:
        f = SingleFolderQuerySet(account=account, folder=f).resolve()
        print(f"GetFolder on folder {f.name} succeeded")
    except Exception as e:
        print(f"ERROR: GetFolder on folder {f} failed")

Worked great - we had a need to check each folder by id and the existing way of achieving this with account.root.walk() seems to be less reliable in recent versions due to the changes Microsoft are bringing in (denying access to Teams related folders etc).

Code we've replaced:

        target_folders = []
        f: Folder
        for f in account.root.walk():
            if f.id in folder_ids:
                logger.debug(f'Iterating through folder: {f.name}')
                target_folders.append(f)
            else:
                logger.debug(f'Skipping folder: [{f.folder_class}] {f.name} {f.id}')

MattGarnettWelsh avatar Apr 30 '24 13:04 MattGarnettWelsh

It’s great that you can use it as a workaround, but I’d really like if you can post the folders printed in the error case. That may give a hint on how we can mitigate this issue.

ecederstrand avatar Apr 30 '24 19:04 ecederstrand

Of course - my apologies!

We actually didn't get any errored folders which is an unexpected outcome considering the above, here are the logs:

GetFolder on folder Calendar succeeded
GetFolder on folder Contacts succeeded
GetFolder on folder {06967759-274D-40B2-A3EB-D7F9E73727D7} succeeded
GetFolder on folder {A9E2BC46-B3A0-4243-B315-60D991004455} succeeded
GetFolder on folder Companies succeeded
GetFolder on folder GAL Contacts succeeded
GetFolder on folder Organizational Contacts succeeded
GetFolder on folder PeopleCentricConversation Buddies succeeded
GetFolder on folder Recipient Cache succeeded
GetFolder on folder Conversation Action Settings succeeded
GetFolder on folder Conversation History succeeded
GetFolder on folder Deleted Items succeeded
GetFolder on folder Drafts succeeded
GetFolder on folder ExternalContacts succeeded
GetFolder on folder Files succeeded
GetFolder on folder Inbox succeeded
GetFolder on folder Journal succeeded
GetFolder on folder Junk Email succeeded
GetFolder on folder Notes succeeded
GetFolder on folder Outbox succeeded
GetFolder on folder Quick Step Settings succeeded
GetFolder on folder Sent Items succeeded
GetFolder on folder Sync Issues succeeded
GetFolder on folder Conflicts succeeded
GetFolder on folder Local Failures succeeded
GetFolder on folder Server Failures succeeded
GetFolder on folder Tasks succeeded
GetFolder on folder Working Set succeeded
GetFolder on folder Yammer Root succeeded
GetFolder on folder Feeds succeeded
GetFolder on folder Inbound succeeded
GetFolder on folder Outbound succeeded

MattGarnettWelsh avatar May 01 '24 12:05 MattGarnettWelsh

Same's for our case, all the GetFolder calls for single folders succeed:

GetFolder on folder Aufgaben succeeded
GetFolder on folder Conversation Action Settings succeeded
GetFolder on folder Dateien succeeded
GetFolder on folder Entwürfe succeeded
GetFolder on folder ExternalContacts succeeded
GetFolder on folder Gelöschte Elemente succeeded
GetFolder on folder Gesendete Elemente succeeded
GetFolder on folder Journal succeeded
GetFolder on folder Junk-E-Mail succeeded
GetFolder on folder Kalender succeeded
GetFolder on folder Geburtstage succeeded
GetFolder on folder Kontakte succeeded
GetFolder on folder {06967759-274D-40B2-A3EB-D7F9E73727D7} succeeded
GetFolder on folder {A9E2BC46-B3A0-4243-B315-60D991004455} succeeded
GetFolder on folder Firmen succeeded
GetFolder on folder GAL Contacts succeeded
GetFolder on folder Organizational Contacts succeeded
GetFolder on folder PeopleCentricConversation Buddies succeeded
GetFolder on folder Recipient Cache succeeded
GetFolder on folder Notizen succeeded
GetFolder on folder Postausgang succeeded
GetFolder on folder Posteingang succeeded
GetFolder on folder Verlauf der Unterhaltung succeeded
GetFolder on folder Yammer-Stamm succeeded
GetFolder on folder Ausgehend succeeded
GetFolder on folder Eingehend succeeded
GetFolder on folder Feeds succeeded

and also, here's the full debugging output for what i reported in a fragmented way earlier. This is what we get after account.msg_folder_root.tree() on the v5.2.1 (with the hardcoded api version 2019): test-hardcoded2019-2.3.txt

oKenneth avatar May 02 '24 08:05 oKenneth

Ok, then it must be a folder somewhere else. Can you try this (testing all folders under root)?

from exchangelib.folders import FolderCollection, SingleFolderQuerySet

for f in FolderCollection(account=account, folders=[account.root]).find_folders():
    try:
        f_or_error = SingleFolderQuerySet(account=account, folder=f).resolve()
    except Exception as e:
        print(f"ERROR: GetFolder on folder {f} failed: {e}")
    if isinstance(f_or_error, Exception):
        print(f"ERROR: GetFolder on folder {f} returned error: {f_or_error}")

ecederstrand avatar May 02 '24 11:05 ecederstrand

Here you go (just to confirm I'm running 5.3.0):

ERROR: Not allowed to access Non IPM folder. failed 'ErrorAccessDenied' object has no attribute 'name'
ERROR: Not allowed to access Non IPM folder. failed 'ErrorAccessDenied' object has no attribute 'name'

The two that errored I can only assume are still the two TeamsMessagesData and TeamChatHistory folders 👍🏽

MattGarnettWelsh avatar May 02 '24 11:05 MattGarnettWelsh

Super weird. None of that triggered an ErrorInvalidSchemaVersionForMailboxVersion exception, which I was hoping for. The two ErrorAccessDenied are expected and handled gracefully by the code behind account.root.tree()

ecederstrand avatar May 02 '24 11:05 ecederstrand

For the people reporting this, does the issue still appear in exchangelib 5.3.0? And can it be triggered with a simple account.root.tree()?

ecederstrand avatar May 06 '24 08:05 ecederstrand

for us the expected error came up for the last testing code block you posted @ecederstrand (still on v5.2.1): ERROR: GetFolder on folder Folder (XrmInsights) failed: Tried versions ('Exchange2016', 'Exchange2015_SP1', 'Exchange2015', 'Exchange2013_SP1', 'Exchange2013', 'Exchange2010_SP2', 'Exchange2010_SP1', 'Exchange2010', 'Exchange2007_SP1', 'Exchange2007') but all were invalid

we have not tried v5.3.0 yet. will try do so asap.

oKenneth avatar May 06 '24 08:05 oKenneth

@ecederstrand Yes, the issue still appears in exchangelib 5.3.0. If I do account.root.tree(), I can get the following error:

Traceback (most recent call last):
  File "/opt/homebrew/lib/python3.12/site-packages/cached_property.py", line 70, in __get__
    return obj_dict[name]
           ~~~~~~~~^^^^^^
KeyError: 'folders'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/[email protected]/EwsPlayground/folder_hierarchy.py", line 18, in <module>
    print(account.root.tree())
          ^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.12/site-packages/exchangelib/folders/base.py", line 201, in tree
    children = list(self.children)
               ^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.12/site-packages/exchangelib/folders/collections.py", line 46, in __len__
    return len(self.folders)
               ^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.12/site-packages/cached_property.py", line 74, in __get__
    return obj_dict.setdefault(name, self.func(obj))
                                     ^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.12/site-packages/exchangelib/folders/collections.py", line 43, in folders
    return tuple(self._folders)
           ^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.12/site-packages/exchangelib/folders/roots.py", line 98, in get_children
    for f in self._folders_map.values():
             ^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.12/site-packages/exchangelib/folders/roots.py", line 175, in _folders_map
    for f in FolderCollection(account=self.account, folders=distinguished_folders).resolve():
  File "/opt/homebrew/lib/python3.12/site-packages/exchangelib/folders/collections.py", line 335, in resolve
    yield from self.__class__(account=self.account, folders=resolveable_folders).get_folders(
  File "/opt/homebrew/lib/python3.12/site-packages/exchangelib/folders/collections.py", line 403, in get_folders
    yield from GetFolder(account=self.account).call(
  File "/opt/homebrew/lib/python3.12/site-packages/exchangelib/services/get_folder.py", line 51, in _elems_to_objs
    for folder, elem in zip(self.folders, elems):
  File "/opt/homebrew/lib/python3.12/site-packages/exchangelib/services/common.py", line 278, in _chunked_get_elements
    yield from self._get_elements(payload=payload_func(chunk, **kwargs))
  File "/opt/homebrew/lib/python3.12/site-packages/exchangelib/services/common.py", line 299, in _get_elements
    yield from self._response_generator(payload=payload)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.12/site-packages/exchangelib/services/common.py", line 262, in _response_generator
    response = self._get_response_xml(payload=payload)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.12/site-packages/exchangelib/services/common.py", line 423, in _get_response_xml
    raise self.NO_VALID_SERVER_VERSIONS(f"Tried versions {self._api_versions_to_try()} but all were invalid")
exchangelib.errors.ErrorInvalidSchemaVersionForMailboxVersion: Tried versions ('Exchange2016', 'Exchange2015_SP1', 'Exchange2015', 'Exchange2013_SP1', 'Exchange2013', 'Exchange2010_SP2', 'Exchange2010_SP1', 'Exchange2010', 'Exchange2007_SP1', 'Exchange2007') but all were invalid

If I revert the version to 5.2.0, the issue is gone.

quzhi1 avatar May 06 '24 20:05 quzhi1

Thanks for the stack trace! It reveals that it's an issue with distinguished folders, not child folders of the root folder. This snippet should reveal the culprit(s):

from exchangelib.folders import SingleFolderQuerySet
from exchangelib.properties import DistinguishedFolderId, Mailbox

distinguished_folders = [
    cls(
        _distinguished_id=DistinguishedFolderId(
            id=cls.DISTINGUISHED_FOLDER_ID,
            mailbox=Mailbox(email_address=account.primary_smtp_address),
        ),
        root=account.root,
    )
    for cls in account.root.WELLKNOWN_FOLDERS
    if cls.get_folder_allowed and cls.supports_version(account.version)
]
for f in distinguished_folders:
    try:
        f_or_error = SingleFolderQuerySet(account=account, folder=f).resolve()
    except Exception as e:
        print(f"ERROR: GetFolder on folder {f.DISTINGUISHED_FOLDER_ID!r} failed: {e!r}")
        continue
    if isinstance(f_or_error, Exception):
        print(f"ERROR: GetFolder on folder {f.DISTINGUISHED_FOLDER_ID!r} failed: {f_or_error!r}")

ecederstrand avatar May 07 '24 13:05 ecederstrand

I ran the script above using exchangelib 5.3.0 and an Exchange 2016 mailbox. This is the output I got:

ERROR: GetFolder on folder 'allcategorizeditems' failed: ErrorInvalidSchemaVersionForMailboxVersion("Tried versions ('Exchange2015', 'Exchange2016', 'Exchange2015_SP1', 'Exchange2013_SP1', 'Exchange2013', 'Exchange2010_SP2', 'Exchange2010_SP1', 'Exchange2010', 'Exchange2007_SP1', 'Exchange2007') but all were invalid")
ERROR: GetFolder on folder 'directory' failed: ErrorInvalidOperation('The distinguished folder name is unrecognized.')
ERROR: GetFolder on folder 'dlppolicyevaluation' failed: ErrorInvalidSchemaVersionForMailboxVersion("Tried versions ('Exchange2015', 'Exchange2016', 'Exchange2015_SP1', 'Exchange2013_SP1', 'Exchange2013', 'Exchange2010_SP2', 'Exchange2010_SP1', 'Exchange2010', 'Exchange2007_SP1', 'Exchange2007') but all were invalid")
ERROR: GetFolder on folder 'onenotepagepreviews' failed: ErrorInvalidSchemaVersionForMailboxVersion("Tried versions ('Exchange2015', 'Exchange2016', 'Exchange2015_SP1', 'Exchange2013_SP1', 'Exchange2013', 'Exchange2010_SP2', 'Exchange2010_SP1', 'Exchange2010', 'Exchange2007_SP1', 'Exchange2007') but all were invalid")
ERROR: GetFolder on folder 'qedcdefaultretention' failed: ErrorInvalidSchemaVersionForMailboxVersion("Tried versions ('Exchange2015', 'Exchange2016', 'Exchange2015_SP1', 'Exchange2013_SP1', 'Exchange2013', 'Exchange2010_SP2', 'Exchange2010_SP1', 'Exchange2010', 'Exchange2007_SP1', 'Exchange2007') but all were invalid")
ERROR: GetFolder on folder 'qedclongretention' failed: ErrorInvalidSchemaVersionForMailboxVersion("Tried versions ('Exchange2015', 'Exchange2016', 'Exchange2015_SP1', 'Exchange2013_SP1', 'Exchange2013', 'Exchange2010_SP2', 'Exchange2010_SP1', 'Exchange2010', 'Exchange2007_SP1', 'Exchange2007') but all were invalid")
ERROR: GetFolder on folder 'qedcmediumretention' failed: ErrorInvalidSchemaVersionForMailboxVersion("Tried versions ('Exchange2015', 'Exchange2016', 'Exchange2015_SP1', 'Exchange2013_SP1', 'Exchange2013', 'Exchange2010_SP2', 'Exchange2010_SP1', 'Exchange2010', 'Exchange2007_SP1', 'Exchange2007') but all were invalid")
ERROR: GetFolder on folder 'qedcshortretention' failed: ErrorInvalidSchemaVersionForMailboxVersion("Tried versions ('Exchange2015', 'Exchange2016', 'Exchange2015_SP1', 'Exchange2013_SP1', 'Exchange2013', 'Exchange2010_SP2', 'Exchange2010_SP1', 'Exchange2010', 'Exchange2007_SP1', 'Exchange2007') but all were invalid")
ERROR: GetFolder on folder 'quarantinedemail' failed: ErrorInvalidSchemaVersionForMailboxVersion("Tried versions ('Exchange2015', 'Exchange2016', 'Exchange2015_SP1', 'Exchange2013_SP1', 'Exchange2013', 'Exchange2010_SP2', 'Exchange2010_SP1', 'Exchange2010', 'Exchange2007_SP1', 'Exchange2007') but all were invalid")
ERROR: GetFolder on folder 'quarantinedemaildefaultcategory' failed: ErrorInvalidSchemaVersionForMailboxVersion("Tried versions ('Exchange2015', 'Exchange2016', 'Exchange2015_SP1', 'Exchange2013_SP1', 'Exchange2013', 'Exchange2010_SP2', 'Exchange2010_SP1', 'Exchange2010', 'Exchange2007_SP1', 'Exchange2007') but all were invalid")
ERROR: GetFolder on folder 'recoverableitemssubstrateholds' failed: ErrorInvalidSchemaVersionForMailboxVersion("Tried versions ('Exchange2015', 'Exchange2016', 'Exchange2015_SP1', 'Exchange2013_SP1', 'Exchange2013', 'Exchange2010_SP2', 'Exchange2010_SP1', 'Exchange2010', 'Exchange2007_SP1', 'Exchange2007') but all were invalid")
ERROR: GetFolder on folder 'shortnotes' failed: ErrorInvalidSchemaVersionForMailboxVersion("Tried versions ('Exchange2015', 'Exchange2016', 'Exchange2015_SP1', 'Exchange2013_SP1', 'Exchange2013', 'Exchange2010_SP2', 'Exchange2010_SP1', 'Exchange2010', 'Exchange2007_SP1', 'Exchange2007') but all were invalid")
ERROR: GetFolder on folder 'usercuratedcontacts' failed: ErrorInvalidSchemaVersionForMailboxVersion("Tried versions ('Exchange2015', 'Exchange2016', 'Exchange2015_SP1', 'Exchange2013_SP1', 'Exchange2013', 'Exchange2010_SP2', 'Exchange2010_SP1', 'Exchange2010', 'Exchange2007_SP1', 'Exchange2007') but all were invalid")

laurachan avatar May 07 '24 23:05 laurachan

Thanks for the output! That narrows down the problem considerably. It seems these distinguished folders are not supported on your Exchange version, which means we can just annotate these folders with supported_from = EXCHANGE_O365

Which exact version is your Exchange server? Please post the output of print(account.version).

ecederstrand avatar May 08 '24 10:05 ecederstrand

The referenced commit should fix the issue for you, @laurachan

If others still have the issue even after https://github.com/ecederstrand/exchangelib/commit/be0cd9f48997e31158690cc2cd5ea53fa9610ec5 then please run the code posted in https://github.com/ecederstrand/exchangelib/issues/1301#issuecomment-2098478709 and post the output in this thread.

ecederstrand avatar May 08 '24 11:05 ecederstrand

@ecederstrand I added the following to my requirements.txt:

git+https://github.com/ecederstrand/exchangelib.git@be0cd9f48997e31158690cc2cd5ea53fa9610ec5

But when I run the debugging script https://github.com/ecederstrand/exchangelib/issues/1301#issuecomment-2098478709, I am still getting this error:

ERROR: GetFolder on folder 'allcategorizeditems' failed: ErrorInvalidSchemaVersionForMailboxVersion("Tried versions ('Exchange2016', 'Exchange2015_SP1', 'Exchange2015', 'Exchange2013_SP1', 'Exchange2013', 'Exchange2010_SP2', 'Exchange2010_SP1', 'Exchange2010', 'Exchange2007_SP1', 'Exchange2007') but all were invalid")
ERROR: GetFolder on folder 'conflicts' failed: ErrorFolderNotFound('The specified folder could not be found in the store.')
ERROR: GetFolder on folder 'directory' failed: ErrorInvalidOperation('The distinguished folder name is unrecognized.')
ERROR: GetFolder on folder 'dlppolicyevaluation' failed: ErrorInvalidSchemaVersionForMailboxVersion("Tried versions ('Exchange2016', 'Exchange2015_SP1', 'Exchange2015', 'Exchange2013_SP1', 'Exchange2013', 'Exchange2010_SP2', 'Exchange2010_SP1', 'Exchange2010', 'Exchange2007_SP1', 'Exchange2007') but all were invalid")
ERROR: GetFolder on folder 'localfailures' failed: ErrorFolderNotFound('The specified folder could not be found in the store.')
ERROR: GetFolder on folder 'onenotepagepreviews' failed: ErrorInvalidSchemaVersionForMailboxVersion("Tried versions ('Exchange2016', 'Exchange2015_SP1', 'Exchange2015', 'Exchange2013_SP1', 'Exchange2013', 'Exchange2010_SP2', 'Exchange2010_SP1', 'Exchange2010', 'Exchange2007_SP1', 'Exchange2007') but all were invalid")
ERROR: GetFolder on folder 'qedcdefaultretention' failed: ErrorInvalidSchemaVersionForMailboxVersion("Tried versions ('Exchange2016', 'Exchange2015_SP1', 'Exchange2015', 'Exchange2013_SP1', 'Exchange2013', 'Exchange2010_SP2', 'Exchange2010_SP1', 'Exchange2010', 'Exchange2007_SP1', 'Exchange2007') but all were invalid")
ERROR: GetFolder on folder 'qedclongretention' failed: ErrorInvalidSchemaVersionForMailboxVersion("Tried versions ('Exchange2016', 'Exchange2015_SP1', 'Exchange2015', 'Exchange2013_SP1', 'Exchange2013', 'Exchange2010_SP2', 'Exchange2010_SP1', 'Exchange2010', 'Exchange2007_SP1', 'Exchange2007') but all were invalid")
ERROR: GetFolder on folder 'qedcmediumretention' failed: ErrorInvalidSchemaVersionForMailboxVersion("Tried versions ('Exchange2016', 'Exchange2015_SP1', 'Exchange2015', 'Exchange2013_SP1', 'Exchange2013', 'Exchange2010_SP2', 'Exchange2010_SP1', 'Exchange2010', 'Exchange2007_SP1', 'Exchange2007') but all were invalid")
ERROR: GetFolder on folder 'qedcshortretention' failed: ErrorInvalidSchemaVersionForMailboxVersion("Tried versions ('Exchange2016', 'Exchange2015_SP1', 'Exchange2015', 'Exchange2013_SP1', 'Exchange2013', 'Exchange2010_SP2', 'Exchange2010_SP1', 'Exchange2010', 'Exchange2007_SP1', 'Exchange2007') but all were invalid")
ERROR: GetFolder on folder 'quarantinedemail' failed: ErrorInvalidSchemaVersionForMailboxVersion("Tried versions ('Exchange2016', 'Exchange2015_SP1', 'Exchange2015', 'Exchange2013_SP1', 'Exchange2013', 'Exchange2010_SP2', 'Exchange2010_SP1', 'Exchange2010', 'Exchange2007_SP1', 'Exchange2007') but all were invalid")
ERROR: GetFolder on folder 'quarantinedemaildefaultcategory' failed: ErrorInvalidSchemaVersionForMailboxVersion("Tried versions ('Exchange2016', 'Exchange2015_SP1', 'Exchange2015', 'Exchange2013_SP1', 'Exchange2013', 'Exchange2010_SP2', 'Exchange2010_SP1', 'Exchange2010', 'Exchange2007_SP1', 'Exchange2007') but all were invalid")
ERROR: GetFolder on folder 'recoverableitemssubstrateholds' failed: ErrorInvalidSchemaVersionForMailboxVersion("Tried versions ('Exchange2016', 'Exchange2015_SP1', 'Exchange2015', 'Exchange2013_SP1', 'Exchange2013', 'Exchange2010_SP2', 'Exchange2010_SP1', 'Exchange2010', 'Exchange2007_SP1', 'Exchange2007') but all were invalid")
ERROR: GetFolder on folder 'serverfailures' failed: ErrorFolderNotFound('The specified folder could not be found in the store.')
ERROR: GetFolder on folder 'shortnotes' failed: ErrorInvalidSchemaVersionForMailboxVersion("Tried versions ('Exchange2016', 'Exchange2015_SP1', 'Exchange2015', 'Exchange2013_SP1', 'Exchange2013', 'Exchange2010_SP2', 'Exchange2010_SP1', 'Exchange2010', 'Exchange2007_SP1', 'Exchange2007') but all were invalid")
ERROR: GetFolder on folder 'syncissues' failed: ErrorFolderNotFound('The specified folder could not be found in the store.')
ERROR: GetFolder on folder 'usercuratedcontacts' failed: ErrorInvalidSchemaVersionForMailboxVersion("Tried versions ('Exchange2016', 'Exchange2015_SP1', 'Exchange2015', 'Exchange2013_SP1', 'Exchange2013', 'Exchange2010_SP2', 'Exchange2010_SP1', 'Exchange2010', 'Exchange2007_SP1', 'Exchange2007') but all were invalid")

quzhi1 avatar May 08 '24 17:05 quzhi1

@quzhi1 What version of Exchange is that? print(account.version)

ecederstrand avatar May 08 '24 17:05 ecederstrand

@ecederstrand The version is

Build=15.1.2507.39, API=Exchange2016, Fullname=Microsoft Exchange Server 2016

quzhi1 avatar May 08 '24 17:05 quzhi1

@quzhi1 I'm a bit sceptical whether you were actually running exchangelib at that commit, because when I run the test those folders are not in the list of distinguished folders when I hardcode the server version to 15.1.2507.39, even before I start talking to the server:

account.version = Version(build=Build(15, 1, 2507, 39), api_version="Exchange2016")
distinguished_folders = [
    cls(
        _distinguished_id=DistinguishedFolderId(
            id=cls.DISTINGUISHED_FOLDER_ID,
            mailbox=Mailbox(email_address=account.primary_smtp_address),
        ),
        root=account.root,
    )
    for cls in account.root.WELLKNOWN_FOLDERS
    if cls.get_folder_allowed and cls.supports_version(account.version)
]
print(sorted([f.DISTINGUISHED_FOLDER_ID for f in distinguished_folders]))
# prints:
# ['allcontacts', 'allitems', 'allpersonmetadata', 'calendar', 'companycontacts', 'conflicts', 'contacts', 'conversationhistory', 'deleteditems', 'directory', 'drafts', 'favorites', 'fromfavoritesenders', 'imcontactlist', 'inbox', 'inference', 'journal', 'junkemail', 'localfailures', 'msgfolderroot', 'mycontacts', 'notes', 'outbox', 'peoplecentricconversationbuddies', 'peopleconnect', 'quickcontacts', 'recipientcache', 'recoverableitemsdeletions', 'recoverableitemspurges', 'recoverableitemsroot', 'recoverableitemsversions', 'relevantcontacts', 'searchfolders', 'sentitems', 'serverfailures', 'sharepointnotifications', 'syncissues', 'tasks', 'temporarysaves', 'todosearch', 'voicemail']

Can you try again, checking that the installed exchangelib has the patches?

ecederstrand avatar May 12 '24 17:05 ecederstrand

Hi @ecederstrand,

This is my requirements.txt file:

git+https://github.com/ecederstrand/exchangelib.git@be0cd9f48997e31158690cc2cd5ea53fa9610ec5
lxml==5.1.0
gunicorn==21.2.0
Flask==3.0.2

This is the output of my pip install:

> pip install -r requirements.txt --break-system-packages
Collecting git+https://github.com/ecederstrand/exchangelib.git@be0cd9f48997e31158690cc2cd5ea53fa9610ec5 (from -r requirements.txt (line 1))
  Cloning https://github.com/ecederstrand/exchangelib.git (to revision be0cd9f48997e31158690cc2cd5ea53fa9610ec5) to /private/var/folders/xf/0y4zn8n937947rh9gwry45yc0000gp/T/pip-req-build-x6rnp72e
  Running command git clone --filter=blob:none --quiet https://github.com/ecederstrand/exchangelib.git /private/var/folders/xf/0y4zn8n937947rh9gwry45yc0000gp/T/pip-req-build-x6rnp72e
  Running command git rev-parse -q --verify 'sha^be0cd9f48997e31158690cc2cd5ea53fa9610ec5'
  Running command git fetch -q https://github.com/ecederstrand/exchangelib.git be0cd9f48997e31158690cc2cd5ea53fa9610ec5
  Resolved https://github.com/ecederstrand/exchangelib.git to commit be0cd9f48997e31158690cc2cd5ea53fa9610ec5
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Installing backend dependencies ... done
  Preparing metadata (pyproject.toml) ... done
Requirement already satisfied: lxml==5.1.0 in /opt/homebrew/lib/python3.12/site-packages (from -r requirements.txt (line 2)) (5.1.0)
Requirement already satisfied: gunicorn==21.2.0 in /opt/homebrew/lib/python3.12/site-packages (from -r requirements.txt (line 3)) (21.2.0)
Requirement already satisfied: Flask==3.0.2 in /opt/homebrew/lib/python3.12/site-packages (from -r requirements.txt (line 4)) (3.0.2)
Requirement already satisfied: packaging in /opt/homebrew/lib/python3.12/site-packages (from gunicorn==21.2.0->-r requirements.txt (line 3)) (24.0)
Requirement already satisfied: Werkzeug>=3.0.0 in /opt/homebrew/lib/python3.12/site-packages (from Flask==3.0.2->-r requirements.txt (line 4)) (3.0.2)
Requirement already satisfied: Jinja2>=3.1.2 in /opt/homebrew/lib/python3.12/site-packages (from Flask==3.0.2->-r requirements.txt (line 4)) (3.1.3)
Requirement already satisfied: itsdangerous>=2.1.2 in /opt/homebrew/lib/python3.12/site-packages (from Flask==3.0.2->-r requirements.txt (line 4)) (2.2.0)
Requirement already satisfied: click>=8.1.3 in /opt/homebrew/lib/python3.12/site-packages (from Flask==3.0.2->-r requirements.txt (line 4)) (8.1.7)
Requirement already satisfied: blinker>=1.6.2 in /opt/homebrew/lib/python3.12/site-packages (from Flask==3.0.2->-r requirements.txt (line 4)) (1.7.0)
Requirement already satisfied: cached-property in /opt/homebrew/lib/python3.12/site-packages (from exchangelib==5.3.0->-r requirements.txt (line 1)) (1.5.2)
Requirement already satisfied: defusedxml>=0.6.0 in /opt/homebrew/lib/python3.12/site-packages (from exchangelib==5.3.0->-r requirements.txt (line 1)) (0.7.1)
Requirement already satisfied: dnspython>=2.2.0 in /opt/homebrew/lib/python3.12/site-packages (from exchangelib==5.3.0->-r requirements.txt (line 1)) (2.6.1)
Requirement already satisfied: isodate in /opt/homebrew/lib/python3.12/site-packages (from exchangelib==5.3.0->-r requirements.txt (line 1)) (0.6.1)
Requirement already satisfied: oauthlib in /opt/homebrew/lib/python3.12/site-packages (from exchangelib==5.3.0->-r requirements.txt (line 1)) (3.2.2)
Requirement already satisfied: pygments in /opt/homebrew/lib/python3.12/site-packages (from exchangelib==5.3.0->-r requirements.txt (line 1)) (2.17.2)
Requirement already satisfied: requests>=2.31.0 in /opt/homebrew/lib/python3.12/site-packages (from exchangelib==5.3.0->-r requirements.txt (line 1)) (2.31.0)
Requirement already satisfied: requests-ntlm>=0.2.0 in /opt/homebrew/lib/python3.12/site-packages (from exchangelib==5.3.0->-r requirements.txt (line 1)) (1.2.0)
Requirement already satisfied: requests-oauthlib in /opt/homebrew/lib/python3.12/site-packages (from exchangelib==5.3.0->-r requirements.txt (line 1)) (2.0.0)
Requirement already satisfied: tzdata in /opt/homebrew/lib/python3.12/site-packages (from exchangelib==5.3.0->-r requirements.txt (line 1)) (2024.1)
Requirement already satisfied: tzlocal in /opt/homebrew/lib/python3.12/site-packages (from exchangelib==5.3.0->-r requirements.txt (line 1)) (5.2)
Requirement already satisfied: MarkupSafe>=2.0 in /opt/homebrew/lib/python3.12/site-packages (from Jinja2>=3.1.2->Flask==3.0.2->-r requirements.txt (line 4)) (2.1.5)
Requirement already satisfied: charset-normalizer<4,>=2 in /opt/homebrew/lib/python3.12/site-packages (from requests>=2.31.0->exchangelib==5.3.0->-r requirements.txt (line 1)) (3.3.2)
Requirement already satisfied: idna<4,>=2.5 in /opt/homebrew/lib/python3.12/site-packages (from requests>=2.31.0->exchangelib==5.3.0->-r requirements.txt (line 1)) (3.6)
Requirement already satisfied: urllib3<3,>=1.21.1 in /opt/homebrew/lib/python3.12/site-packages (from requests>=2.31.0->exchangelib==5.3.0->-r requirements.txt (line 1)) (2.2.1)
Requirement already satisfied: certifi>=2017.4.17 in /opt/homebrew/lib/python3.12/site-packages (from requests>=2.31.0->exchangelib==5.3.0->-r requirements.txt (line 1)) (2024.2.2)
Requirement already satisfied: cryptography>=1.3 in /opt/homebrew/lib/python3.12/site-packages (from requests-ntlm>=0.2.0->exchangelib==5.3.0->-r requirements.txt (line 1)) (42.0.5)
Requirement already satisfied: pyspnego>=0.1.6 in /opt/homebrew/lib/python3.12/site-packages (from requests-ntlm>=0.2.0->exchangelib==5.3.0->-r requirements.txt (line 1)) (0.10.2)
Requirement already satisfied: six in /opt/homebrew/lib/python3.12/site-packages (from isodate->exchangelib==5.3.0->-r requirements.txt (line 1)) (1.16.0)
Requirement already satisfied: cffi>=1.12 in /opt/homebrew/lib/python3.12/site-packages (from cryptography>=1.3->requests-ntlm>=0.2.0->exchangelib==5.3.0->-r requirements.txt (line 1)) (1.16.0)
Requirement already satisfied: pycparser in /opt/homebrew/lib/python3.12/site-packages (from cffi>=1.12->cryptography>=1.3->requests-ntlm>=0.2.0->exchangelib==5.3.0->-r requirements.txt (line 1)) (2.22)
Building wheels for collected packages: exchangelib
  Building wheel for exchangelib (pyproject.toml) ... done
  Created wheel for exchangelib: filename=exchangelib-5.3.0-py3-none-any.whl size=242208 sha256=2fdd2308a936807dcd15e33f0d10f95801d8aa11a6cca56023d9d9f9a214ea9c
  Stored in directory: /Users/[email protected]/Library/Caches/pip/wheels/14/a3/57/defe0203df20a356f61885eb3940935f01a8b6d568c4295e5c
Successfully built exchangelib
Installing collected packages: exchangelib
  Attempting uninstall: exchangelib
    Found existing installation: exchangelib 5.2.0
    Uninstalling exchangelib-5.2.0:
      Successfully uninstalled exchangelib-5.2.0
Successfully installed exchangelib-5.3.0

Then I ran the script again:

> /opt/homebrew/bin/python3 /Users/[email protected]/EwsPlayground/debugging_version.py
exchange version:  Build=15.1.2507.39, API=Exchange2016, Fullname=Microsoft Exchange Server 2016
ERROR: GetFolder on folder 'conflicts' failed: ErrorFolderNotFound('The specified folder could not be found in the store.')
ERROR: GetFolder on folder 'directory' failed: ErrorInvalidOperation('The distinguished folder name is unrecognized.')
ERROR: GetFolder on folder 'localfailures' failed: ErrorFolderNotFound('The specified folder could not be found in the store.')
ERROR: GetFolder on folder 'serverfailures' failed: ErrorFolderNotFound('The specified folder could not be found in the store.')
ERROR: GetFolder on folder 'syncissues' failed: ErrorFolderNotFound('The specified folder could not be found in the store.')

quzhi1 avatar May 12 '24 17:05 quzhi1

Great! No more ErrorInvalidSchemaVersionForMailboxVersion errors in the output.

The original bug report was for account.root.tree(). If that now also works without errors, then I believe the bug is fixed.

ecederstrand avatar May 12 '24 17:05 ecederstrand

@ecederstrand If I just run account.root.tree(), I can still see this error:

Traceback (most recent call last):
  File "/opt/homebrew/lib/python3.12/site-packages/cached_property.py", line 70, in __get__
    return obj_dict[name]
           ~~~~~~~~^^^^^^
KeyError: 'folders'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/[email protected]/EwsPlayground/debugging_version.py", line 14, in <module>
    account.root.tree()
  File "/opt/homebrew/lib/python3.12/site-packages/exchangelib/folders/base.py", line 201, in tree
    children = list(self.children)
               ^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.12/site-packages/exchangelib/folders/collections.py", line 46, in __len__
    return len(self.folders)
               ^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.12/site-packages/cached_property.py", line 74, in __get__
    return obj_dict.setdefault(name, self.func(obj))
                                     ^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.12/site-packages/exchangelib/folders/collections.py", line 43, in folders
    return tuple(self._folders)
           ^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.12/site-packages/exchangelib/folders/roots.py", line 98, in get_children
    for f in self._folders_map.values():
             ^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.12/site-packages/exchangelib/folders/roots.py", line 190, in _folders_map
    for f in (
  File "/opt/homebrew/lib/python3.12/site-packages/exchangelib/folders/queryset.py", line 158, in _query
    for f, complex_f in zip(resolveable_folders, complex_folders):
  File "/opt/homebrew/lib/python3.12/site-packages/exchangelib/folders/collections.py", line 403, in get_folders
    yield from GetFolder(account=self.account).call(
  File "/opt/homebrew/lib/python3.12/site-packages/exchangelib/services/get_folder.py", line 51, in _elems_to_objs
    for folder, elem in zip(self.folders, elems):
  File "/opt/homebrew/lib/python3.12/site-packages/exchangelib/services/common.py", line 278, in _chunked_get_elements
    yield from self._get_elements(payload=payload_func(chunk, **kwargs))
  File "/opt/homebrew/lib/python3.12/site-packages/exchangelib/services/common.py", line 299, in _get_elements
    yield from self._response_generator(payload=payload)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.12/site-packages/exchangelib/services/common.py", line 262, in _response_generator
    response = self._get_response_xml(payload=payload)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.12/site-packages/exchangelib/services/common.py", line 423, in _get_response_xml
    raise self.NO_VALID_SERVER_VERSIONS(f"Tried versions {self._api_versions_to_try()} but all were invalid")
exchangelib.errors.ErrorInvalidSchemaVersionForMailboxVersion: Tried versions ('Exchange2016', 'Exchange2015_SP1', 'Exchange2015', 'Exchange2013_SP1', 'Exchange2013', 'Exchange2010_SP2', 'Exchange2010_SP1', 'Exchange2010', 'Exchange2007_SP1', 'Exchange2007') but all were invalid

But if I run your script in https://github.com/ecederstrand/exchangelib/issues/1301#issuecomment-2106319802, I can get the result:

['allcontacts', 'allitems', 'allpersonmetadata', 'calendar', 'companycontacts', 'conflicts', 'contacts', 'conversationhistory', 'deleteditems', 'directory', 'drafts', 'favorites', 'fromfavoritesenders', 'imcontactlist', 'inbox', 'inference', 'journal', 'junkemail', 'localfailures', 'msgfolderroot', 'mycontacts', 'notes', 'outbox', 'peoplecentricconversationbuddies', 'peopleconnect', 'quickcontacts', 'recipientcache', 'recoverableitemsdeletions', 'recoverableitemspurges', 'recoverableitemsroot', 'recoverableitemsversions', 'relevantcontacts', 'searchfolders', 'sentitems', 'serverfailures', 'sharepointnotifications', 'syncissues', 'tasks', 'temporarysaves', 'todosearch', 'voicemail']

quzhi1 avatar May 12 '24 18:05 quzhi1

@quzhi1 Ok, well at least I can see from the stack trace that you got past the initial fetching of distinguished folders, which is good, and the FindFolder call also succeeded. Can you try running the snippet I posted in https://github.com/ecederstrand/exchangelib/issues/1301#issuecomment-2090249004?

ecederstrand avatar May 12 '24 18:05 ecederstrand