Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

creating Account() from disabled user throws TransportError #1342

Open
seanstory opened this issue Nov 15, 2024 · 1 comment
Open

creating Account() from disabled user throws TransportError #1342

seanstory opened this issue Nov 15, 2024 · 1 comment

Comments

@seanstory
Copy link

Describe the bug
Reported in elastic/connectors#2931

Psudocode:

configuration = get_configuration()
for user in list_users_from_graph_api():
  user_account = Account(
                primary_smtp_address=user.get("attributes", {}).get("mail"),
                config=configuration,
                access_type=IMPERSONATION,
            )

When trying to create an Account object for users pulled from the MS Graph API, we're getting a stack trace like:

  File "/workspaces/elastic_connectors/connectors/sources/outlook.py", line 451, in get_user_accounts
    user_account = Account(
  File "/workspaces/elastic_connectors/lib/python3.10/site-packages/exchangelib/account.py", line 205, in __init__
    self.version = self.protocol.version.copy()
  File "/workspaces/elastic_connectors/lib/python3.10/site-packages/exchangelib/protocol.py", line 480, in version
    self.config.version = Version.guess(self, api_version_hint=self.api_version_hint)
  File "/workspaces/elastic_connectors/lib/python3.10/site-packages/exchangelib/version.py", line 206, in guess
    raise TransportError(f"No valid version headers found in response ({e!r})")
exchangelib.errors.TransportError: No valid version headers found in response (ErrorNonExistentMailbox('The SMTP address has no mailbox associated with it.'))

Upon further investigation, it seems that this is happening because the graph API returns all users, active and disabled. But if a user has "accountEnabled": false, attempts to retrieve their mailbox raises errors.

To Reproduce

  • create a User in your azure portal
  • take note of the user's email address
  • un-check the box for the user's "Account Enabled" setting
  • wait a few minutes
  • create an Account() object with exchangelib, using the disabled user's email address
  • get a TransportError

Expected behavior

If only enabled users are supported for an Account object, I'd expect to see that in the docstring, or a note that this type of error might be raised for a disabled user.

Otherwise, I'd expect the Account object to initialize successfully, and just represent a disabled account.

Additional context
Python 3.11
exchangelib 5.4.0

@ecederstrand
Copy link
Owner

Thanks for the report. It's been this way for many years, and I think at this point too much code depends on Account() throwing ErrorNonExistentMailbox if the server does not know the email address.

It's not possible to know whether the reason for the exception is that the account is disabled, but feel free to suggest a better wording for the docsting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants