-
Notifications
You must be signed in to change notification settings - Fork 32
Open
Description
The solution provided in issue 3 had a minor bug:
#3
Under client.py:
33 response = self.parent.error(
34 'http', req, response, response.code, response.msg,
35 response.info)
It passed in response.info method when it should be issue response.info()
Once this was fixed and no longer raised an exception, it expose an additional bug where it would recursively call the http_error_401 due to self.parent.error recalling this method. So to fix this, I found I needed to apply the following solution to raise the appropriate HTTP Error for 404.
class CustomHTTPNtlmAuthHandler(HTTPNtlmAuthHandler):
""" A version of HTTPNtlmAuthHandler that handles errors (better).
The default version doesn't use `self.parent.open` in it's
error handler, and completely bypasses the normal `OpenerDirector`
call chain, most importantly `HTTPErrorProcessor.http_response`,
which normally raises an error for 'bad' http status codes..
"""
def http_error_401(self, req, fp, code, msg, hdrs):
response = HTTPNtlmAuthHandler.http_error_401(self, req, fp, code, msg, hdrs)
if not (200 <= response.code < 300):
- response = self.parent.error(
- 'http', req, response, response.code, response.msg,
- response.info)
+ if response.code == 401:
+ raise HTTPError(req.get_full_url(), response.code, response.msg, response.info(), fp)
+ else:
+ response = self.parent.error(
+ 'http', req, response, response.code, response.msg,
+ response.info())
return response
Metadata
Metadata
Assignees
Labels
No labels