Exchangelib Python-仍然验证错误

问题描述

由于遇到了新的错误,我开始了有关Python Exchangelib的新话题。

解决了503服务器响应错误(Exchangelib error in Python: www-authenticate),我现在在200服务器响应上获得身份验证错误!

这是我的代码

creds = Credentials(
    username=username,password=pw)

config = Configuration(
    server='company.it',retry_policy=FaultTolerance(max_wait=3600),credentials=creds
)

account = Account(
    primary_smtp_address=mailbox_mail,credentials=creds,autodiscover=False,access_type=DELEGATE,config=config
)

m = Message(
    account=account,subject='Test',body='Test',to_recipients=['my_mail']
)
m.send()

下面您将看到成功的ko运行日志:

2020-10-14 14:25:18 DEBUG    Converted retries value: 3 -> Retry(total=3,connect=None,read=None,redirect=None,status=None)
2020-10-14 14:25:18 DEBUG    Making request: POST https://oauth2.googleapis.com/token
2020-10-14 14:25:18 DEBUG    Starting new HTTPS connection (1): oauth2.googleapis.com:443
2020-10-14 14:25:18 DEBUG    https://oauth2.googleapis.com:443 "POST /token HTTP/1.1" 200 None
2020-10-14 14:25:18 DEBUG    Starting new HTTPS connection (1): storage.googleapis.com:443
2020-10-14 14:25:18 DEBUG    https://storage.googleapis.com:443 "GET /storage/v1/b/w3-dp-prod-technical-accounts?projection=noAcl HTTP/1.1" 200 633
2020-10-14 14:25:18 DEBUG    https://storage.googleapis.com:443 "GET /storage/v1/b/w3-dp-prod-technical-accounts/o/username.pw?projection=noAcl HTTP/1.1" 200 831
2020-10-14 14:25:18 DEBUG    https://storage.googleapis.com:443 "GET /download/storage/v1/b/w3-dp-prod-technical-accounts/o/username.pw?generation=1599555404559507&alt=media HTTP/1.1" 200 12
2020-10-14 14:25:18 DEBUG    Waiting for _protocol_cache_lock
2020-10-14 14:25:18 DEBUG    Protocol __call__ cache miss. Adding key '('https://company.it/EWS/Exchange.asmx',Credentials('companydomain\\username','********'))'
2020-10-14 14:25:18 DEBUG    Requesting b'<?xml version=\'1.0\' encoding=\'utf-8\'?>\n<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"><s:Header><t:RequestServerVersion Version="Exchange2019"/></s:Header><s:Body><m:ResolveNames ReturnFullContactData="false"><m:UnresolvedEntry>companydomain\\username</m:UnresolvedEntry></m:ResolveNames></s:Body></s:Envelope>' from https://company.it/EWS/Exchange.asmx
2020-10-14 14:25:18 DEBUG    Trying to get service auth type for https://company.it/EWS/Exchange.asmx
2020-10-14 14:25:18 DEBUG    Starting new HTTPS connection (1): company.it:443
2020-10-14 14:25:18 DEBUG    https://company.it:443 "POST /EWS/Exchange.asmx HTTP/1.1" 401 0
2020-10-14 14:25:18 DEBUG    Request headers: {'User-Agent': 'exchangelib/3.2.0 (python-requests/2.24.0)','Accept-Encoding': 'gzip,deflate','Accept': '*/*','Connection': 'keep-alive','Content-Type': 'text/xml; charset=utf-8','Content-Length': '466'}
2020-10-14 14:25:18 DEBUG    Response headers: {'Server': 'Microsoft-IIS/8.5','WWW-Authenticate': 'Negotiate,NTLM','request-id': '32e8ab39-3fe0-45eb-ba30-02044fa511ad','X-Powered-By': 'ASP.NET,ARR/3.0','X-FEServer': 'WIVEX05','Date': 'Wed,14 Oct 2020 14:25:17 GMT','Content-Length': '0'}
2020-10-14 14:25:18 DEBUG    Auth type is NTLM
2020-10-14 14:25:18 DEBUG    Server company.it: Created session 24740
2020-10-14 14:25:18 DEBUG    Asking server for version info using API version Exchange2019
2020-10-14 14:25:18 DEBUG    Trying API version Exchange2019
2020-10-14 14:25:18 DEBUG    Server company.it: Waiting for session
2020-10-14 14:25:18 DEBUG    Server company.it: Got session 24740
2020-10-14 14:25:18 DEBUG    Session 24740 thread 140265555482368: retry 0 timeout 120 POST'ing to https://company.it/EWS/Exchange.asmx after 10s wait
2020-10-14 14:25:18 DEBUG    Starting new HTTPS connection (1): company.it:443
2020-10-14 14:25:18 DEBUG    https://company.it:443 "POST /EWS/Exchange.asmx HTTP/1.1" 401 0
2020-10-14 14:25:19 DEBUG    https://company.it:443 "POST /EWS/Exchange.asmx HTTP/1.1" 401 0
2020-10-14 14:25:19 DEBUG    https://company.it:443 "POST /EWS/Exchange.asmx HTTP/1.1" 500 None
2020-10-14 14:25:19 DEBUG    Retry: 0
Waited: 10
Timeout: 120
Session: 24740
Thread: 140265555482368
Auth type: <requests_ntlm.requests_ntlm.HttpNtlmAuth object at 0x7f9218dab1f0>
URL: https://company.it/EWS/Exchange.asmx
HTTP adapter: <requests.adapters.HTTPAdapter object at 0x7f9218dab310>
Allow redirects: False
Streaming: False
Response time: 0.3869298470017384
Status code: 500
Request headers: {'User-Agent': 'exchangelib/3.2.0 (python-requests/2.24.0)','Connection': 'Keep-Alive','Content-Length': '466','Authorization': 'NTLM TlRMTVNTUAADAAAAGAAYAIQAAADcANwAnAAAABAAEABYAAAAHAAcAGgAAAAAAAAAhAAAABAAEAB4AQAANYKJ4gYBsR0AAAAPUauGfP5BEx1tr2/Pp7Nb9FcASQBOAEQAUgBPAE8AVABkAGEAdABhAGcAbwB2AGUAcgBuAGEAbgBjAGUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAZpJtJGTo61CzgabwaCRu3AEBAAAAAAAA59Cn1zWi1gHycq09ncNZ4gAAAAACABAAVwBJAE4ARABSAE8ATwBUAAEADgBXAEkAVgBFAFgAMAAzAAQAGAB3AGkAbgBkAC4AcgBvAG8AdAAuAGkAdAADACgAVwBJAFYARQBYADAAMwAuAHcAaQBuAGQALgByAG8AbwB0AC4AaQB0AAUADgByAG8AbwB0AC4AaQB0AAcACADn0KfXNaLWAQYABAACAAAACgAQAIOzO8atC5Er5IrZ/IcCH8YAAAAAAAAAANEPCwLavYNpL8t3tlDAU8c='}
Response headers: {'Cache-Control': 'private','Transfer-Encoding': 'chunked','Server': 'Microsoft-IIS/8.5','Set-Cookie': 'exchangecookie=1f6b04d84c6b44c4bf808da9c8227f6f; expires=Thu,14-Oct-2021 14:25:19 GMT; path=/; HttpOnly,X-BackEndCookie=S-1-5-21-842925246-725345543-1163770773-1933531=u56Lnp2ejJqBy82bmZqeycbSx8ucztLLxsjH0seczJ3SnMjKxprNmpnGyZyZgYHNz83P0s7O0s7Mq87Lxc3Kxc7GgY2QkIvRlouBzg==; expires=Fri,13-Nov-2020 14:25:19 GMT; path=/EWS; secure; HttpOnly','Persistent-Auth': 'true','request-id': 'f32b4d27-c209-48f2-af3e-77ad275eaca1','X-CalculatedBETarget': 'wivex01.company.root.it','X-DiagInfo': 'WIVEX01','X-BEServer': 'WIVEX01','X-AspNet-Version': '4.0.30319','X-FEServer': 'WIVEX03',14 Oct 2020 14:25:19 GMT'}
Request data: b'<?xml version=\'1.0\' encoding=\'utf-8\'?>\n<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"><s:Header><t:RequestServerVersion Version="Exchange2019"/></s:Header><s:Body><m:ResolveNames ReturnFullContactData="false"><m:UnresolvedEntry>companydomain\\username</m:UnresolvedEntry></m:ResolveNames></s:Body></s:Envelope>'
Response data: b'<?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><s:Fault><faultcode xmlns:a="http://schemas.microsoft.com/exchange/services/2006/types">a:ErrorInvalidRequest</faultcode><faultstring xml:lang="en-US">The request is invalid.</faultstring><detail><e:ResponseCode xmlns:e="http://schemas.microsoft.com/exchange/services/2006/errors">ErrorInvalidRequest</e:ResponseCode><e:Message xmlns:e="http://schemas.microsoft.com/exchange/services/2006/errors">The request is invalid.</e:Message></detail></s:Fault></s:Body></s:Envelope>'

2020-10-14 14:25:19 DEBUG    No retry: wrong status code 500
2020-10-14 14:25:19 DEBUG    Got status code 500 but trying to parse content anyway
2020-10-14 14:25:19 DEBUG    Session 24740 thread 140265555482368: Useful response from https://company.it/EWS/Exchange.asmx
2020-10-14 14:25:19 DEBUG    Server company.it: Releasing session 24740
2020-10-14 14:25:19 DEBUG    No header in XML response
2020-10-14 14:25:19 DEBUG    API version Exchange2019 was invalid
2020-10-14 14:25:19 DEBUG    Trying API version Exchange2016
2020-10-14 14:25:19 DEBUG    Server company.it: Waiting for session
2020-10-14 14:25:19 DEBUG    Server company.it: Got session 24740
2020-10-14 14:25:19 DEBUG    Session 24740 thread 140265555482368: retry 0 timeout 120 POST'ing to https://company.it/EWS/Exchange.asmx after 10s wait
2020-10-14 14:25:19 DEBUG    https://company.it:443 "POST /EWS/Exchange.asmx HTTP/1.1" 200 None
2020-10-14 14:25:19 DEBUG    Retry: 0
Waited: 10
Timeout: 120
Session: 24740
Thread: 140265555482368
Auth type: <requests_ntlm.requests_ntlm.HttpNtlmAuth object at 0x7f9218dab1f0>
URL: https://company.it/EWS/Exchange.asmx
HTTP adapter: <requests.adapters.HTTPAdapter object at 0x7f9218dab310>
Allow redirects: False
Streaming: False
Response time: 0.11851444199783145
Status code: 200
Request headers: {'User-Agent': 'exchangelib/3.2.0 (python-requests/2.24.0)','Cookie': 'X-BackEndCookie=S-1-5-21-842925246-725345543-1163770773-1933531=u56Lnp2ejJqBy82bmZqeycbSx8ucztLLxsjH0seczJ3SnMjKxprNmpnGyZyZgYHNz83P0s7O0s7Mq87Lxc3Kxc7GgY2QkIvRlouBzg==; exchangecookie=1f6b04d84c6b44c4bf808da9c8227f6f','Content-Length': '466'}
Response headers: {'Cache-Control': 'private','Content-Encoding': 'gzip','Vary': 'Accept-Encoding','Set-Cookie': 'exchangecookie=1f6b04d84c6b44c4bf808da9c8227f6f; path=/,'request-id': 'dc947930-fe63-4a5e-b1ce-b95420b9479a','X-CalculatedBETarget': 'wivex02.company.root.it','X-DiagInfo': 'WIVEX02','X-BEServer': 'WIVEX02',14 Oct 2020 14:25:19 GMT'}
Request data: b'<?xml version=\'1.0\' encoding=\'utf-8\'?>\n<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"><s:Header><t:RequestServerVersion Version="Exchange2016"/></s:Header><s:Body><m:ResolveNames ReturnFullContactData="false"><m:UnresolvedEntry>companydomain\\username</m:UnresolvedEntry></m:ResolveNames></s:Body></s:Envelope>'
Response data: b'<?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Header><h:ServerVersionInfo MajorVersion="15" MinorVersion="1" MajorBuildNumber="1713" MinorBuildNumber="5" Version="V2017_07_11" xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/></s:Header><s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><m:ResolveNamesResponse xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"><m:ResponseMessages><m:ResolveNamesResponseMessage ResponseClass="Error"><m:MessageText>No mailbox with such guid.</m:MessageText><m:ResponseCode>ErrorNonExistentMailbox</m:ResponseCode><m:DescriptiveLinkKey>0</m:DescriptiveLinkKey><m:MessageXml><t:Value Name="MailboxGuid">S-1-5-21-842925246-725345543-1163770773-1933531</t:Value></m:MessageXml></m:ResolveNamesResponseMessage></m:ResponseMessages></m:ResolveNamesResponse></s:Body></s:Envelope>'

2020-10-14 14:25:19 DEBUG    No retry: wrong status code 200
2020-10-14 14:25:19 DEBUG    Session 24740 thread 140265555482368: Useful response from https://company.it/EWS/Exchange.asmx
2020-10-14 14:25:19 DEBUG    Server company.it: Releasing session 24740
2020-10-14 14:25:19 DEBUG    API version "Exchange2016" worked but server reports version "V2017_07_11". Using "Exchange2016"
2020-10-14 14:25:19 DEBUG    Found new version (Build=None,API=Exchange2019,Fullname=Microsoft Exchange Server 2019 -> Build=15.1.1713.5,API=Exchange2016,Fullname=Microsoft Exchange Server 2016)
2020-10-14 14:25:19 DEBUG    Added account: mailbox@company.it

这些错误似乎是随机的,我不能只是捕捉到异常然后重试,因为该错误甚至持续显示数小时。然后,代码可以再次正常运行...
我什至尝试了自动发现,但结果相同!

有人可以帮我吗?

再次感谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...