Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

401 - 503 from outlook.office365.com #113

Closed
mcindea opened this issue Apr 6, 2017 · 8 comments
Closed

401 - 503 from outlook.office365.com #113

mcindea opened this issue Apr 6, 2017 · 8 comments

Comments

@mcindea
Copy link

mcindea commented Apr 6, 2017

Can't authenticate on outlook.office365.com apparently, and it looks like it's because of the realm?
Not sure, but i think we need to use realm when authing? Is there a way to enforce it ?

THanks!

DEBUG:exchangelib.protocol:Waiting for _protocol_cache_lock
DEBUG:exchangelib.protocol:Protocol call cache miss. Adding key '('https://outlook.office365.com/EWS/Exchange.asmx', Credentials('xx.xx@on.nokia.com', '********'), False)'
DEBUG:exchangelib.transport:Getting service auth type for https://outlook.office365.com/EWS/Exchange.asmx
DEBUG:exchangelib.transport:Requesting b'<s:Envelope xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:t="http://schemas.mi
DEBUG:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): outlook.office365.com
DEBUG:requests.packages.urllib3.connectionpool:https://outlook.office365.com:443 "POST /EWS/Exchange.asmx HTTP/1.1" 401 0
DEBUG:exchangelib.transport:Request headers: {'Accept-Encoding': 'gzip, deflate', 'User-Agent': 'python-requests/2.13.0', 'Content-Length': '448', 'Accept': '/', 'Content-Type': 'text/xml; charset=utf-8', 'Connection': 'keep-alive'}
DEBUG:exchangelib.transport:Response headers: {'Content-Length': '0', 'X-Powered-By': 'ASP.NET', 'WWW-Authenticate': 'Basic Realm=""', 'Server': 'Microsoft-IIS/8.5', 'Date': 'Thu, 06 Apr 2017 12:00:07 GMT', 'X-FEServer': 'MWHPR14CA0055', 'r
DEBUG:exchangelib.transport:realm:
DEBUG:exchangelib.transport:Auth type is basic
DEBUG:exchangelib.transport:Getting docs auth type for https://outlook.office365.com/EWS/types.xsd
DEBUG:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): outlook.office365.com
DEBUG:requests.packages.urllib3.connectionpool:https://outlook.office365.com:443 "GET /EWS/types.xsd HTTP/1.1" 401 0
DEBUG:exchangelib.transport:Request headers: {'Accept-Encoding': 'gzip, deflate', 'User-Agent': 'python-requests/2.13.0', 'Accept': '/', 'Content-Type': 'text/xml; charset=utf-8', 'Connection': 'keep-alive'}
DEBUG:exchangelib.transport:Response headers: {'X-Powered-By': 'ASP.NET', 'WWW-Authenticate': 'Basic Realm=""', 'Server': 'Microsoft-IIS/8.5', 'X-WSSecurity-Enabled': 'True', 'X-FEServer': 'MWHPR14CA0066', 'Content-Length': '0', 'X-Federati
DEBUG:exchangelib.transport:realm:
DEBUG:exchangelib.transport:Auth type is basic
DEBUG:exchangelib.protocol:Server outlook.office365.com: Created session 24317
DEBUG:exchangelib.protocol:Server outlook.office365.com: Created session 9073
DEBUG:exchangelib.protocol:Server outlook.office365.com: Created session 31633
DEBUG:exchangelib.protocol:Server outlook.office365.com: Created session 14394
DEBUG:exchangelib.version:Asking server for version info
DEBUG:exchangelib.version:Getting https://outlook.office365.com/EWS/types.xsd with auth type HTTPBasicAuth
DEBUG:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): outlook.office365.com
DEBUG:requests.packages.urllib3.connectionpool:https://outlook.office365.com:443 "GET /EWS/types.xsd HTTP/1.1" 503 0
DEBUG:exchangelib.version:Request headers: {'Accept-Encoding': 'gzip, deflate', 'Authorization': 'Basic c29tZXBhc3M===', 'User-Agent': 'python-requests/2.13.0', 'Accept': '/', 'Connection': 'keep-alive'}
DEBUG:exchangelib.version:Response code: 503
DEBUG:exchangelib.version:Response headers: {'X-BEServer': 'VI1PR0701MB2319', 'Retry-After': '30', 'Content-Length': '0', 'X-BackEndHttpStatus': '503', 'Server': 'Microsoft-IIS/8.5', 'X-FEServer': 'MWHPR14CA0055', 'X-DiagInfo': 'VI1PR0701MB
DEBUG:exchangelib.version:Service is unavailable. Unable to get version info from docs
DEBUG:exchangelib.version:Shortname according to https://outlook.office365.com/EWS/types.xsd: None
DEBUG:exchangelib.protocol:Server outlook.office365.com: Waiting for session
DEBUG:exchangelib.protocol:Server outlook.office365.com: Got session 14394
DEBUG:exchangelib.version:Test if service API version is Exchange2016 using auth HTTPBasicAuth
DEBUG:exchangelib.util:Session 14394 thread 12508: retry 0 timeout 120 POST'ing to https://outlook.office365.com/EWS/Exchange.asmx after 0 s wait
DEBUG:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): outlook.office365.com
Traceback (most recent call last):
File "C:\local\Python35-32\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 379, in _make_request
httplib_response = conn.getresponse(buffering=True)
TypeError: getresponse() got an unexpected keyword argument 'buffering'

During handling of the above exception, another exception occurred:

@mcindea
Copy link
Author

mcindea commented Apr 6, 2017

Mention it's an awesome framework, worked with servers located in-house, before we moved to outlook365

@ecederstrand
Copy link
Owner

ecederstrand commented Apr 6, 2017

Strange, was that the full stacktrace? If I remember correctly, TypeError: getresponse() got an unexpected keyword argument 'buffering' is a red herring and the error is actually happening somewhere else.

From what I've seen, Office365 requires you to auth with your email address, but it looks like you're doing that already.

We don't handle Basic authentication ourselves - we use requests.auth.HTTPBasicAuth instead. Maybe it can't handle the empty realm.

@mcindea
Copy link
Author

mcindea commented Apr 6, 2017

Thanks for the fast reply!
actually those were other errors through versions i tested today.Noticed that outlook also send "realm=company.com" , but when using exchangelib it says nothing at realm. And i know some auth protocols use realm too, just a hunch
The error i struggled most with is this loop:

DEBUG:exchangelib.protocol:Protocol __call__ cache miss. Adding key '('https://outlook.office365.com/EWS/Exchange.asmx', Credentials('xx.xx@nokia.com', '********'), False)'
DEBUG:exchangelib.transport:Getting service auth type for https://outlook.office365.com/EWS/Exchange.asmx
DEBUG:exchangelib.transport:Requesting b'<?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" 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>DUMMY</m:UnresolvedEntry></m:ResolveNames></s:Body></s:Envelope>' from https://outlook.office365.com/EWS/Exchange.asmx
DEBUG:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): outlook.office365.com
DEBUG:requests.packages.urllib3.connectionpool:https://outlook.office365.com:443 "POST /EWS/Exchange.asmx HTTP/1.1" 401 0
DEBUG:exchangelib.transport:Request headers: {'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'User-Agent': 'python-requests/2.13.0', 'Content-Type': 'text/xml; charset=utf-8', 'Content-Length': '448'}
DEBUG:exchangelib.transport:Response headers: {'X-Powered-By': 'ASP.NET', 'request-id': '9144c0ef-64a9-42eb-825f-40cba96f9689', 'X-FEServer': 'DB6PR1001CA0004', 'WWW-Authenticate': 'Basic Realm=""', 'Content-Length': '0', 'Server': 'Microsoft-IIS/8.5', 'Date': 'Thu, 06 Apr 2017 14:20:26 GMT'}
DEBUG:exchangelib.transport:realm:
DEBUG:exchangelib.transport:Auth type is basic
DEBUG:exchangelib.transport:Getting docs auth type for https://outlook.office365.com/EWS/types.xsd
DEBUG:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): outlook.office365.com
DEBUG:requests.packages.urllib3.connectionpool:https://outlook.office365.com:443 "GET /EWS/types.xsd HTTP/1.1" 401 0
DEBUG:exchangelib.transport:Request headers: {'Accept': '*/*', 'Connection': 'keep-alive', 'User-Agent': 'python-requests/2.13.0', 'Content-Type': 'text/xml; charset=utf-8', 'Accept-Encoding': 'gzip, deflate'}
DEBUG:exchangelib.transport:Response headers: {'X-WSSecurity-X509Cert-Enabled': 'True', 'request-id': '631a6a8c-326e-44fc-bd85-9e2bd242d536', 'X-WSSecurity-Enabled': 'True', 'WWW-Authenticate': 'Basic Realm=""', 'X-OAuth-Enabled': 'True', 'Server': 'Microsoft-IIS/8.5', 'X-Powered-By': 'ASP.NET', 'X-WSSecurity-For': 'Logon', 'X-FEServer': 'DB6PR1001CA0012', 'X-WSSecurity-SymmetricKey-Enabled': 'True', 'Content-Length': '0', 'Date': 'Thu, 06 Apr 2017 14:20:26 GMT', 'X-FederationTrustTokenIssuerUri': 'urn:federation:MicrosoftOnline'}
DEBUG:exchangelib.transport:realm:
DEBUG:exchangelib.transport:Auth type is basic
DEBUG:exchangelib.protocol:Server outlook.office365.com: Created session 13326
DEBUG:exchangelib.protocol:Server outlook.office365.com: Created session 29768
DEBUG:exchangelib.protocol:Server outlook.office365.com: Created session 18166
DEBUG:exchangelib.protocol:Server outlook.office365.com: Created session 15431
DEBUG:exchangelib.version:Asking server for version info
DEBUG:exchangelib.version:Getting https://outlook.office365.com/EWS/types.xsd with auth type HTTPBasicAuth
DEBUG:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): outlook.office365.com
DEBUG:requests.packages.urllib3.connectionpool:https://outlook.office365.com:443 "GET /EWS/types.xsd HTTP/1.1" 401 0
DEBUG:exchangelib.version:Request headers: {'Accept': '*/*', 'Connection': 'keep-alive', 'User-Agent': 'python-requests/2.13.0', 'Authorization': 'Basic c29tZXBhc3M==', 'Accept-Encoding': 'gzip, deflate'}
DEBUG:exchangelib.version:Response code: 401
DEBUG:exchangelib.version:Response headers: {'X-Powered-By': 'ASP.NET', 'X-BackEndHttpStatus': '401', 'X-DiagInfo': 'VI1PR0701MB2319', 'request-id': '1a3fd869-a1a2-4d78-8672-a973b9de91e2', 'X-FEServer': 'DB6PR1001CA0021', 'WWW-Authenticate': 'Basic Realm="",Basic Realm=""', 'X-BEServer': 'VI1PR0701MB2319', 'Content-Length': '0', 'Date': 'Thu, 06 Apr 2017 14:20:27 GMT', 'Server': 'Microsoft-IIS/8.5', 'X-CalculatedBETarget': 'VI1PR0701MB2319.eurprd07.prod.outlook.com'}
INFO:exchangelib.version:Wrong username or password for https://outlook.office365.com/EWS/types.xsd
DEBUG:exchangelib.protocol:Server outlook.office365.com: Waiting for session
DEBUG:exchangelib.protocol:Server outlook.office365.com: Got session 15431
DEBUG:exchangelib.version:Test if service API version is Exchange2016 using auth HTTPBasicAuth
DEBUG:exchangelib.util:Session 15431 thread 21460: retry 0 timeout 120 POST'ing to https://outlook.office365.com/EWS/Exchange.asmx after 0 s wait
DEBUG:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): outlook.office365.com
DEBUG:requests.packages.urllib3.connectionpool:https://outlook.office365.com:443 "POST /EWS/Exchange.asmx HTTP/1.1" 401 0
DEBUG:exchangelib.util:Retry: 0
Waited: 0
Timeout: 120
Session: 15431
Thread: 21460
Auth type: <requests.auth.HTTPBasicAuth object at 0x02FFCCB0>
URL: https://outlook.office365.com/EWS/Exchange.asmx
Verify: False
Allow redirects: False
Response time: 0:00:00.456079
Status code: 401
Request headers: {'Authorization': 'Basic c29tZXBhc3M==', 'Accept-Encoding': 'compress, gzip', 'Accept': '*/*', 'Connection': 'keep-alive', 'User-Agent': 'python-requests/2.13.0', 'Content-Type': 'text/xml; charset=utf-8', 'Content-Length': '448'}
Response headers: {'X-Powered-By': 'ASP.NET', 'X-BackEndHttpStatus': '401', 'X-BEServer': 'VI1PR0701MB2319', 'request-id': '80c22ff8-86aa-4bce-a93e-a3e197cff95c', 'WWW-Authenticate': 'Basic Realm="",Basic Realm=""', 'Server': 'Microsoft-IIS/8.5', 'X-CalculatedBETarget': 'VI1PR0701MB2319.eurprd07.prod.outlook.com', 'X-DiagInfo': 'VI1PR0701MB2319', 'Set-Cookie': 'exchangecookie=831335399bc74fdbaaf4d0cc3bf4c414; expires=Fri, 06-Apr-2018 14:20:29 GMT; path=/; HttpOnly', 'X-FEServer': 'DB6PR1001CA0015', 'Content-Length': '0', 'Date': 'Thu, 06 Apr 2017 14:20:28 GMT'}
DEBUG:exchangelib.util:Request data: b'<?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" 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>DUMMY</m:UnresolvedEntry></m:ResolveNames></s:Body></s:Envelope>'
DEBUG:exchangelib.util:Response data:
INFO:exchangelib.util:Session 15431 thread 21460: Connection error on URL https://outlook.office365.com/EWS/Exchange.asmx (code 401). Cool down 10 secs

@ecederstrand
Copy link
Owner

Regarding the loop, set Credentials(..., is_service_account=False). This will be fixed in the next version.

@mcindea
Copy link
Author

mcindea commented Apr 6, 2017

hm, so you're saying we could set is_service_account=False, it will bypass the loop and able to access the mailbox? Normally it's not a service account, i do access a "shared mailbox", but currently I use my account, don't have access to a "service account" account yet..
Thanks!

@ecederstrand
Copy link
Owner

"Service account" is just a confusing name for enabling exponential backoff on connection errors in exchangelib. It's purely an exchangelib thing, it has no relation to anything in EWS.

@ecederstrand
Copy link
Owner

Just some ideas for debugging:

I would put exchangelib aside for a moment and check if you can authenticate using just requests. Try sending a POST request to https://outlook.office365.com/EWS/Exchange.asmx.

By the headers, it looks like OAuth authentication is also supported by the server. We don't implement that yet, but you may have luck authenticating with that instead.

I believe some "corporate" Office365 setups will redirect you to some on-site SSO portal for the login process. Maybe that's what's biting you.

@mcindea
Copy link
Author

mcindea commented Apr 7, 2017

Solved it using https://account.activedirectory.windowsazure.com . It generates a random password for android/iphone apps in case we need the mail on cellphone.
Basically, using this password it will bypass the standard password that every user has.
Thanks, man!

@mcindea mcindea closed this as completed Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants