我正在尝试连接到Exchangelib服务,以获得对Outlook的访问,并使用Python中的Exchangelib库对数据进行分组。我遵循下面的文章,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任何解决方案都将不胜感激。提前谢谢。
发布于 2022-07-01 08:27:26
有相同的问题,就像上面所描述的,并且我得到了自动发现:ErrorNonExistentMailbox: The SMTP address has no mailbox associated with it,但是如果您不使用模拟,这似乎是预期的。
https://stackoverflow.com/questions/65356490
复制相似问题