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

[Bug] Cannot working if under retry #103

Open
Kenith opened this issue Jan 4, 2018 · 2 comments
Open

[Bug] Cannot working if under retry #103

Kenith opened this issue Jan 4, 2018 · 2 comments

Comments

@Kenith
Copy link

Kenith commented Jan 4, 2018

Hello,

The requests-ntlm is not working if the requets is under retry:

import requests
from requests.packages.urllib3.util.retry import Retry
from requests.adapters import HTTPAdapter
from requests_ntlm import HttpNtlmAuth

retries = Retry(total=1,
                read=1,
                connect=1,
                backoff_factor=1,
                status_forcelist=[500, 502, 503, 504, 407, 403, 401])

session = requests.Session()
session.verify = False
session.mount('http://', HTTPAdapter(max_retries=retries))
session.mount('https://', HTTPAdapter(max_retries=retries))

session.auth = HttpNtlmAuth('GLOBAL\\***', '***')
res = session.get('https://***.corp.***.com/owa/')

print res.status_code
@Kenith
Copy link
Author

Kenith commented Jan 4, 2018

Found the cause:

because in my status_forcelist, there is: 401.
I removed it, works.

But why with the 401, the request-ntlm not working?

@jborean93
Copy link
Contributor

Probably because NTLM authentication relies on receiving 401 responses. It works like

  • Send un authenticated request
  • Receive 401 response with header that lists supported auth mechanisms
  • Send NTLM negotiate message
  • Receive 401 response with NTLM challenge message
  • Send NTLM authenticate message
  • Receive 200 response as user is now authenticated.

I don't know how the Retry operations change the behaviour but it could be that it adds a hook to 401 responses and continues to try and send the same message (retry) without any of the NTLM messages.

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