在Python中,必须出现这种类型的Oauth soap标头
最近,Microsoft撤回了用于访问Exchange服务的基本身份验证服务。因此,我正在努力将身份验证从基本的基于OAUTH转换为基于OAUTH。但是,在测试过程中,我遇到以下例外。
File "/usr/local/lib/python3.6/site-packages/exchangelib/services/common.py", line 423, in _raise_soap_errors
raise vars(errors)[code](msg)
exchangelib.errors.ErrorInvalidExchangeImpersonationHeaderData: ExchangeImpersonation SOAP header must be present for this type of OAuth token.
我浏览了此处提到的建议 https://github.com/eceders.com/ecedersstrand/ecederstrand/exchangelib/exchangelib/sissues/735555 解决问题,但没有运气解决问题。
#实现有关
redentials = OAuth2Credentials(
client_id=self.client_id, client_secret=self.client_secret, tenant_id=self.tenant_id,
identity=Identity(smtp_address=self.email_address)
)
log.info(f"Credentials ==>{credentials}")
config = Configuration(server=self.email_server, credentials=credentials, auth_type=OAUTH2, version=Version(build=EXCHANGE_O365))
self.account = Account(self.email_address, access_type=DELEGATE, config=config)
解决上述例外的任何建议都是很大的帮助。提前致谢
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您使用client_credentials流时,您需要在ews中使用模仿,例如,
您
还需要确保您的申请注册具有FULL_ACCESS_AS_APP许可,并且已同意以查看 https://learn.microsoft.com/en-us/exchange/client-developer/exchange-web-services/how-to-to-to-authenticate-an-ews-an-ews-application-by-usish-using-oauth
When your using the client_credentials flow you need to use impersonation in EWS eg change
to
You also need to make sure you Application registration has the full_access_as_app permission and its consented to see https://learn.microsoft.com/en-us/exchange/client-developer/exchange-web-services/how-to-authenticate-an-ews-application-by-using-oauth