2

Before showing you the error there is some backstory: Until a couple days ago the code worked just fine. Then they did a migration, before to login we used a link like "https://webmail.domain.it/owa/[email protected]" now they migrated on cloud using the link "https://outlook.office365.com/mail".

the code is pretty straight:

class MyProxyAdapter(requests.adapters.HTTPAdapter):
    def send(self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None):
        proxies = {
            'http': 'proxy',
            'https': 'proxy',
        }
        return super().send(request, stream=stream, timeout=timeout, verify=verify, cert=cert, proxies=proxies)
    
def getAccount():
    try:
        user= "UT-*****-DEV"
        psw = "Password"

        BaseProtocol.HTTP_ADAPTER_CLS = MyProxyAdapter
        config = Configuration(server='outlook.office365.com',
          retry_policy=FaultTolerance(max_wait=900), credentials=Credentials(user,  psw)
        )
        return Account(
            '[email protected]',
            config=config,
            autodiscover=True, access_type=DELEGATE
        )
    except Exception as e:
        print(f"Get data error: {e}...")
        return None

Before the migration this code worked just fine. Now it's throwing "wrong credentials". I've tried to deactive the autodiscover feature and instead of throwing wrong credentials the command account.protocol.version gives a warning: WARNING:exchangelib.util:Server requested back off until 2025-07-31 08:42:34.617995. Sleeping 9.998383 seconds. I've also tried to log in using "[email protected]" instead of "UT-XXX-DEV" but it still doesn't work. I've also tried to force the proxy using os.environ or using NoVerifyHTTPAdapter as the protocol but nothing changes.

Do someone have any tips or had this problem before?

2 Answers 2

2

Basic (username/password) authentication is no longer supported on office365.com. You need to set up OAuth, as described in https://ecederstrand.github.io/exchangelib/#impersonation-oauth-on-office-365

Sign up to request clarification or add additional context in comments.

Comments

1

After looking on other forums the reason may be that EWS doesn't support NTLM authentication on cloud but only on prem. I'm still not 100% sure this is the reason why but I'm going to procede by creating a service principal anyway.

Thank you

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.