python-3.x - 连接到 Exchange Web 服务时出现无效凭据错误
问题描述
我正在尝试使用 Python 中的 Exchangelib 库连接到 Exchange Web 服务以访问 Outlook 和 Teams 数据。我正在关注以下文章, https://github.com/ecederstrand/exchangelib/issues/747
下面是代码片段,
from exchangelib import IMPERSONATION, Account, Credentials, OAuth2Credentials, \
Configuration, OAUTH2, Identity
client_id='XXX'
client_secret='XXX'
tenant_id='XXX'
user= 'XXX@YYY.onmicrosoft.com'
credentials = OAuth2Credentials(
client_id=client_id,
client_secret=client_secret,
tenant_id=tenant_id,
identity=Identity(primary_smtp_address=user)
)
config = Configuration(
credentials=credentials,
auth_type=OAUTH2,
service_endpoint="https://outlook.office365.com/EWS/Exchange.asmx",
)
account = Account(
user,
config=config,
autodiscover=False,
access_type=IMPERSONATION,
)
print(account.root.all().count())
我仍然正确地提供了所有凭据,我收到一个无效的凭据错误,如下所示。
886 if response.status_code == 401 and protocol.retry_policy.fail_fast:
887 # This is a login failure
--> 888 raise UnauthorizedError('Invalid credentials for %s' % response.url)
889 if 'TimeoutException' in response.headers:
890 raise response.headers['TimeoutException']
UnauthorizedError: Invalid credentials for https://outlook.office365.com/EWS/Exchange.asmx
任何解决方案表示赞赏。提前致谢。
解决方案
推荐阅读
- c# - 我们如何将材料添加到 Google Classroom API Coursework 对象?
- python - Python smtplib 接受日历事件
- c++ - 当仅在一行上提示输入一次时,如何确保用户输入名字和姓氏?
- html - 可以使用 style="float: right;" 的元素吗 与一系列“float:left;”中的第一个对齐 元素?
- javascript - setInterval(function(), 5) 不适用于 iOS 或任何移动设备
- javascript - 使用 React Hooks 的倒数计时器
- javascript - Discord.js 使用 404 获取 5 条特定消息完全失败
- scala - 如何从 Spark Dataframes 中的列中获取常量值
- haskell - Haskell - Let 和 Where 中的多个语句导致错误
- sql - 更新嵌套的 bigquery json 元素