Python exchangelib OAuth2身份验证失败

Python exchangelib OAuth2身份验证失败,python,oauth-2.0,exchangewebservices,exchangelib,Python,Oauth 2.0,Exchangewebservices,Exchangelib,由于微软显然已经为ExchangeWeb服务提供了EOL的基本身份验证,我正在尝试将我的Python应用程序转换为使用OAuth2。Python 3.8、exchangelib 3.2.1、ms exchange版本未知但为最新版本。有关守则如下: from exchangelib import Credentials, Account, Message, Mailbox, ExtendedProperty, Configuration, \ OA

由于微软显然已经为ExchangeWeb服务提供了EOL的基本身份验证,我正在尝试将我的Python应用程序转换为使用OAuth2。Python 3.8、exchangelib 3.2.1、ms exchange版本未知但为最新版本。有关守则如下:

from exchangelib import Credentials, Account, Message, Mailbox, ExtendedProperty, Configuration, \
                        OAuth2Credentials, OAuth2AuthorizationCodeCredentials, Identity, OAUTH2
from oauthlib.oauth2 import OAuth2Token

    credentials = OAuth2Credentials(client_id="xxxxxxxx-xxxx-etc", client_secret="xxxxxxxxxxxxx-etc",
                                    tenant_id="xxxxxxxx-xxxx-etc")
    config=Configuration(credentials=credentials, auth_type=OAUTH2)
    acct = Account(primary_smtp_address='testAddr@example.com', config=config, autodiscover=True)
结果是:

ValueError: Auth type must be 'OAuth 2.0' for credentials type OAuth2Credentials
DEBUG:exchangelib.protocol:Server autodiscover.example.com: Closing sessions
正在BaseProtocol的开头引发异常。请在protocol.py中创建_oauth2_session():

        if self.auth_type != OAUTH2:
            raise ValueError('Auth type must be %r for credentials type OAuth2Credentials' % OAUTH2)
非常简单…除了我在代码中明确指定了auth_type=OAUTH2之外。最终我发现正在创建第二个配置对象;第一个类型为OAUTH2,如预期的那样,第二个类型为NTLM,这就是创建_OAUTH2_会话的类型,但它正在失败。第二个实例携带我的凭据,但服务端点参数从None变为autodiscover.example.com/autodiscover/autodiscover.xml。作为自动发现过程的一部分,这是有意义的(我认为),但为什么要使用第二个实例,为什么要更改auth类型??我被难住了。非常感谢任何/所有帮助。

这看起来像个bug。应该允许OAuth进行自动发现,但它显然不适合您。我会打开一个调试器,找出
auth\u type
值重置的位置。我没有启用OAuth的EWS服务器,所以我自己无法测试。

这看起来像个bug。应该允许OAuth进行自动发现,但它显然不适合您。我会打开一个调试器,找出
auth\u type
值重置的位置。我没有启用OAuth的EWS服务器,所以我自己无法测试它