-
Notifications
You must be signed in to change notification settings - Fork 101
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
www-authenticate #36
Comments
It means no Auth challenge header was received. =) |
Hi Lukasa. Thanks for the very prompt response. Ok so you may have to dumb this down a little for me. Basically I am trying to download a file over webdav from a sharepoint site and I think that the problem is that the site is using ntlm authentication. So if I am not getting an Auth challenge header does that mean that the site is not using NTLM? |
I suspect so. I'm not sure what your code looks like, but if you can get hold of the |
Looking at the project you linked @mentaal it seems like it was last updated in December but was still depending on requests 0.11.1. This library is maintained for requests >= 2.2.0 and is likely highly incompatible with the version of requests that library is using. |
Ok guys thanks for the feedback here. Lukasa, I'll try what you suggested. Cheers |
I'm running into the same error with the following response, where the
|
I'm running into the same issue. It seems the web server sometimes responds with 'www-authenticate' and other times with 'WWW-Authenticate'. Function response_hook uses a safe get on the headers dictionary to extract www-authenticate. If found, it calls retry_using_http_NTLM_auth with auth_header_field="www-authenticate". In retry_using_http_NTLM_auth, a new request is made and on the response (response2), there is an unsafe call on the headers dictionary: auth_header_value = response2.headers[auth_header_field]. We cannot assume that because response (first response) had a header "www-authenticate", that response2 will also have a header "www-authenticate". It seems a solution should be in the line of:
|
It seems my web server issue is NOT due to case sensitivity. The requests package uses a case insensitive dictionary, which handles this just fine. However, there is an assumption in retry_using_http_NTLM_auth. We cannot assume that because In my case, it seems the server sometimes (randomly) responds with an http 400. This triggers an exception in requests_ntlm because the header does not have "www-authenticate". Instead of quitting gracefully and informing that the web server did not like the request, it raises a KeyError. HTTP for response2
Error message
|
A workaround I've found, which might or not conform to what you expect or what you might want - is to return In function retry_using_http_NTLM_auth, instead of (line 132-133) # get the challenge
auth_header_value = response2.headers[auth_header_field] We do: # get the challenge
try:
auth_header_value = response2.headers[auth_header_field]
except:
# Failed to get authentication header after first step of NTLM
# Return original response and quit
return response Another, perhaps better way, to handle this could be to raise an Exception stating something like Perhaps something like (untested code): # confirm response2 is valid
response2.raise_for_status()
# get the challenge or raise an error
try:
auth_header_value = response2.headers[auth_header_field]
except keyError:
raise ValueError(f"Failed to negotiate NTLM authentication with server. Server response headers do not contain '{auth_header_field}': {response2.headers}") |
As for me, it was that the server responded with a 400 (Invalid request) : Using requests debugger (from requests documentation). I got those logs :
To me, if the server responds with Invalid request, we should not expect www-authenticate headers (maybe I'm incorrect, I did not read the NTLM specifications) |
Hi there, I tried using your library and I am also trying to use your library within a different github project https://github.com/Crypt0s/python-webdav
I get the following error:
File "<corporate_path_here>/python-webdav/requests-ntlm/requests_ntlm/requests_ntlm.py", line 57, in retry_using_http_NTLM_auth
auth_header_value = response2.headers[auth_header_field]
File "<corporate_path_here>/python-webdav/requests/requests/structures.py", line 77, in getitem
return self._store[key.lower()][1]
KeyError: 'www-authenticate'
Any ideas what this error means?
The text was updated successfully, but these errors were encountered: