Skip to content

V1Meta does not handle authenication error properly with HTTPNTLMAuthHandler #25

Open

Description

@little-button

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

Activity

  1. aarcro commented on Nov 24, 2015

    @aarcro

    An additional issue here. 'ntlm' not in auth_header_value.lower(), then response is None, and .code is an attribute error.

  2. added a commit that references this issue on Sep 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions