Script raises 'TypeError: Credentials.__init__() got an unexpected keyword argument 'auth_method'

823 views Asked by At

I am writing script to send email messages.

Here is the main file code:

import config
from exchangelib import Credentials, Account, Message, Mailbox
from exchangelib.errors import UnauthorizedError, TransportError

credentials = Credentials(
    username=config.exchange_username,
    password=config.exchange_password,
    auth_method='ntlm',
)
account = Account(
    primary_smtp_address=config.exchange_email,
    credentials=credentials,
    autodiscover=True,
)

here is the config file code:

token = "6666666666:GGGGvbe-cHjjDjuUtRggHtGfFFfF"
exchange_username = 'Asdfgh'
exchange_password = 'AkjhHhgHGhV'
exchange_email = '[email protected]'
exchange_server = 'https://some.mail.gov/owa/'

I found on the Internet that the error occurs in the Credentials(username=config.exchange_username, password=config.exchange_password, auth_method='ntlm') line, since there is no auth_method parameter in the Credentials constructor in the exchangelib library. Instead, the auth_type parameter is used. Changed, but the error occurs again already with the description of auth_type

If I remove auth_method='ntlm' from the code, it gives an error "Authorization error on the Exchange server: No compatible auth type was reported by server"

1

There are 1 answers

0
Erik Cederstrand On

The Credentials class does not accept an auth_method argument.

If you want to specify the authentication type for exchangelib to use, create a Configuration instance and use the auth_type argument:

credentials = Credentials(username="foo", password="bar")
config = Configuration(
    credentials=credentials,
    auth_type=NTLM,
)
account = Account(
    primary_smtp_address="[email protected]",
    autodiscover=True,
    config=config,
)

There are plenty of examples on how to connect to the server at https://ecederstrand.github.io/exchangelib/#setup-and-connecting