python 脚本引发“TypeError:凭据,__init__()获得了意外的关键字参数“auth_method”

cwtwac6a  于 2023-04-19  发布在  Python
关注(0)|答案(1)|浏览(152)

我正在编写发送电子邮件的脚本。
下面是主文件代码:

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

下面是配置文件代码:

token = "6666666666:GGGGvbe-cHjjDjuUtRggHtGfFFfF"
exchange_username = 'Asdfgh'
exchange_password = 'AkjhHhgHGhV'
exchange_email = 'Asdfgh@example.com'
exchange_server = 'https://some.mail.gov/owa/'

我在互联网上发现错误发生在Credentials(username=config.exchange_username, password=config.exchange_password, auth_method='ntlm')行,因为exchangeelib库的Credentials构造函数中没有auth_method参数。而是使用auth_type参数。已更改,但错误再次发生,说明为auth_type
如果我从代码中删除auth_method='ntlm',它会给出一个错误“Authorization error on the Exchange server:服务器未报告兼容的身份验证类型”

myzjeezk

myzjeezk1#

Credentials类不接受auth_method参数。
如果要指定exchangeelib要使用的身份验证类型,请创建Configuration示例并使用auth_type参数:

credentials = Credentials(username="foo", password="bar")
config = Configuration(
    credentials=credentials,
    auth_type=NTLM,
)
account = Account(
    primary_smtp_address="foo@example.com",
    autodiscover=True,
    config=config,
)

在www.example.com上有很多关于如何连接到服务器的示例https://ecederstrand.github.io/exchangelib/#setup-and-connecting

相关问题