Giter VIP home page Giter VIP logo

Comments (45)

quzhi1 avatar quzhi1 commented on June 23, 2024 2

@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.

from exchangelib.

ecederstrand avatar ecederstrand commented on June 23, 2024 1

@quzhi1 A workaround would be to mark the folder to exclude GetFolder requests:

from exchangelib.folders import NonDeletableFolder, NON_DELETABLE_FOLDERS

class XrmInsights(NonDeletableFolder):
    get_folder_allowed = False

NON_DELETABLE_FOLDERS.append(XrmInsights)
account.root.tree()

Your suggestion is an option for a more permanent solution, but the EWS docs aren't always totally up-to-date, and don't specify when there are differences between Exchange versions, so I'd like to avoid that solution if possible.

from exchangelib.

laurachan avatar laurachan commented on June 23, 2024 1

Never mind, I think the error might have been on my end and caused by accidentally having two versions of exchangelib present. After getting pip to uninstall exchangelib and then rerunning the command to install 17ea29a, the errors disappeared. Sorry about that!

from exchangelib.

oKenneth avatar oKenneth commented on June 23, 2024 1

with v5.4.0 the ErrorInvalidSchemaVersionForMailboxVersion vanishes at our end as well. thanks a lot @ecederstrand

from exchangelib.

ecederstrand avatar ecederstrand commented on June 23, 2024

Thanks for the report!

We made the change in API version from Exchange2019 to Exchange2016 in #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)

from exchangelib.

oKenneth avatar oKenneth commented on June 23, 2024

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?

from exchangelib.

ecederstrand avatar ecederstrand commented on June 23, 2024

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.

from exchangelib.

laurachan avatar laurachan commented on June 23, 2024

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.

from exchangelib.

ecederstrand avatar ecederstrand commented on June 23, 2024

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.

from exchangelib.

oKenneth avatar oKenneth commented on June 23, 2024

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.

from exchangelib.

ecederstrand avatar ecederstrand commented on June 23, 2024

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")

from exchangelib.

ecederstrand avatar ecederstrand commented on June 23, 2024

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

from exchangelib.

MattGarnettWelsh avatar MattGarnettWelsh commented on June 23, 2024

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}')

from exchangelib.

ecederstrand avatar ecederstrand commented on June 23, 2024

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.

from exchangelib.

MattGarnettWelsh avatar MattGarnettWelsh commented on June 23, 2024

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

from exchangelib.

oKenneth avatar oKenneth commented on June 23, 2024

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

from exchangelib.

ecederstrand avatar ecederstrand commented on June 23, 2024

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}")

from exchangelib.

MattGarnettWelsh avatar MattGarnettWelsh commented on June 23, 2024

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 👍🏽

from exchangelib.

ecederstrand avatar ecederstrand commented on June 23, 2024

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()

from exchangelib.

ecederstrand avatar ecederstrand commented on June 23, 2024

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()?

from exchangelib.

oKenneth avatar oKenneth commented on June 23, 2024

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.

from exchangelib.

ecederstrand avatar ecederstrand commented on June 23, 2024

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}")

from exchangelib.

laurachan avatar laurachan commented on June 23, 2024

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")

from exchangelib.

ecederstrand avatar ecederstrand commented on June 23, 2024

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).

from exchangelib.

ecederstrand avatar ecederstrand commented on June 23, 2024

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

If others still have the issue even after be0cd9f then please run the code posted in #1301 (comment) and post the output in this thread.

from exchangelib.

quzhi1 avatar quzhi1 commented on June 23, 2024

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

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

But when I run the debugging script #1301 (comment), 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")

from exchangelib.

ecederstrand avatar ecederstrand commented on June 23, 2024

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

from exchangelib.

quzhi1 avatar quzhi1 commented on June 23, 2024

@ecederstrand The version is

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

from exchangelib.

ecederstrand avatar ecederstrand commented on June 23, 2024

@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?

from exchangelib.

quzhi1 avatar quzhi1 commented on June 23, 2024

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.')

from exchangelib.

ecederstrand avatar ecederstrand commented on June 23, 2024

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.

from exchangelib.

quzhi1 avatar quzhi1 commented on June 23, 2024

@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 #1301 (comment), 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']

from exchangelib.

ecederstrand avatar ecederstrand commented on June 23, 2024

@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 #1301 (comment)?

from exchangelib.

quzhi1 avatar quzhi1 commented on June 23, 2024

@ecederstrand Sure.
This is the script: https://github.com/quzhi1/EwsPlayground/blob/main/debugging_find_folders.py
Here is the output:

> /opt/homebrew/bin/python3 /Users/[email protected]/EwsPlayground/debugging_find_folders.py
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

from exchangelib.

ecederstrand avatar ecederstrand commented on June 23, 2024

Hmmm, why would the XrmInsights folder be the only folder that fails, and fail so badly that the request XML is discarded as invalid by the server?

It's possible that the server for some reason does not like one or more of the additional fields that we request in the GetFolder call. Also, it would be nice to see the actual XML request that the server throws an error on. Can you run this and post the XML request that triggers the ErrorInvalidSchemaVersionForMailboxVersion error response?

If the additional_fields=[] line succeeds and the additional_fields=additional_fields line fails, we need to find the field(s) that trigger the server error. I added some code to do that.

from exchangelib.folders import FolderCollection
from exchangelib.util import PrettyXmlHandler

logging.basicConfig(level=logging.DEBUG, handlers=[PrettyXmlHandler()])
for f in FolderCollection(account=account, folders=[account.root]).find_folders():
    if f.name != "XrmInsights":
        continue
    fc = FolderCollection(account=account, folders=[f])
    additional_fields = fc.get_folder_fields(target_cls=fc._get_target_cls())
    list(fc.get_folders(additional_fields=set()))
    for field in additional_fields:
        try:
            list(fc.get_folders(additional_fields={field}))
        except Exception as e:
            print(f"ERROR: GetFolder with field {field!r} failed: {e!r}")
    list(fc.get_folders(additional_fields=additional_fields))

from exchangelib.

quzhi1 avatar quzhi1 commented on June 23, 2024

@ecederstrand This is the script I ran: https://github.com/quzhi1/EwsPlayground/blob/main/debugging_xrm_insights.py

And this is the console output: https://github.com/quzhi1/EwsPlayground/blob/main/output.txt

from exchangelib.

ecederstrand avatar ecederstrand commented on June 23, 2024

Thanks! In the FindFolder response, the folder is returned as:

<t:Folder>
    <t:FolderId Id="AQMkAExAAAA" ChangeKey="AABGS"/>
    <t:DisplayName>XrmInsights</t:DisplayName>
    <t:DistinguishedFolderId>XrmInsights</t:DistinguishedFolderId>
    [...]
</t:Folder>

but any attempt to call GetFolder with this DistinguishedFolderId value returns the SOAP error The request is invalid..

I don't have any solutions for this problem right now.

from exchangelib.

quzhi1 avatar quzhi1 commented on June 23, 2024

In this case, can we hardcode the XrmInsights as an unretrievable folder and skip it?

Although the response contains XrmInsights as a distinguished folder id, it is not documented in exchange: https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/distinguishedfolderid. We can also make a hard-coded allow-list and only allow retrieving those folders by distinguished id.

from exchangelib.

ecederstrand avatar ecederstrand commented on June 23, 2024

For anyone else in this thread having the same issue, please post here whether you also only have trouble with the XrmInsights folder, or also other folders. Running the code in #1301 (comment) should tell you that, but only after installing an exchangelib that includes be0cd9f

from exchangelib.

ecederstrand avatar ecederstrand commented on June 23, 2024

@quzhi1 I believe I have a better solution in 1e77961. With some luck, you can now run account.root.tree() without any workarounds.

from exchangelib.

quzhi1 avatar quzhi1 commented on June 23, 2024

@ecederstrand I am still seeing the same version errors with this commit.

Running this script: https://github.com/quzhi1/EwsPlayground/blob/main/debugging_find_folders.py

Output:

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

Running this script: https://github.com/quzhi1/EwsPlayground/blob/main/debugging_xrm_insights.py

Output: https://github.com/quzhi1/EwsPlayground/blob/main/output.txt

from exchangelib.

laurachan avatar laurachan commented on June 23, 2024

Apologies for the delay in replying. I tried installing from commit be0cd9f and re-ran the test script but found I still got the same error message as before.

I subsequently tried installing from commit 1e77961 and the test script produced far fewer errors, but there was still an invalid schema version error that caused my code to crash when I tried to access account.inbox.parent. Interestingly, the folder that caused the error this time was not one of the ones that errored out before.

ERROR: GetFolder on folder 'calendarsearchcache' 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.')
An unexpected error occurred. Review the error log for details.

I still got the same error after installing 17ea29a

from exchangelib.

ecederstrand avatar ecederstrand commented on June 23, 2024

@laurachan That's unexpected. calendarsearchcache was fixed to not be recognized as a distinguished folder in 17ea29a and I tested that specific folder on my test account which exhibited the error.

Can you please double check that your exchangelib does in fact contain 17ea29a, and whether account.root.tree() succeeds or not with that commit?

from exchangelib.

laurachan avatar laurachan commented on June 23, 2024
$ python3 -m pip install git+https://github.com/ecederstrand/exchangelib.git@17ea29a6569eb7c6dcdcb1f81c9ba3b017b9f2d9
Collecting git+https://github.com/ecederstrand/exchangelib.git@17ea29a6569eb7c6dcdcb1f81c9ba3b017b9f2d9
  Cloning https://github.com/ecederstrand/exchangelib.git (to revision 17ea29a6569eb7c6dcdcb1f81c9ba3b017b9f2d9) to /tmp/pip-req-build-ss941vte
  Running command git clone --filter=blob:none --quiet https://github.com/ecederstrand/exchangelib.git /tmp/pip-req-build-ss941vte
  Running command git rev-parse -q --verify 'sha^17ea29a6569eb7c6dcdcb1f81c9ba3b017b9f2d9'
  Running command git fetch -q https://github.com/ecederstrand/exchangelib.git 17ea29a6569eb7c6dcdcb1f81c9ba3b017b9f2d9
  Running command git checkout -q 17ea29a6569eb7c6dcdcb1f81c9ba3b017b9f2d9
  Resolved https://github.com/ecederstrand/exchangelib.git to commit 17ea29a6569eb7c6dcdcb1f81c9ba3b017b9f2d9

ErrorInvalidSchemaVersionForMailboxVersion still occurred on calendarsearchcache after that. I also confirmed that both account.root.tree() and account.inbox.parent error out as a result.

from exchangelib.

ecederstrand avatar ecederstrand commented on June 23, 2024

Glad to hear it works for you as well!

from exchangelib.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.