requests-ntlm
requests-ntlm copied to clipboard
[Bug] Cannot working if under retry
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
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?
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.