From 3650e6cd935e0d940c376350602064674c317e61 Mon Sep 17 00:00:00 2001 From: Patterson Date: Fri, 3 Nov 2017 14:36:40 -0500 Subject: [PATCH 1/3] Warning for when credentials still yield a 401 error --- news/4833.bugfix | 1 + src/pip/_internal/download.py | 15 ++++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 news/4833.bugfix diff --git a/news/4833.bugfix b/news/4833.bugfix new file mode 100644 index 00000000000..ee96e03c122 --- /dev/null +++ b/news/4833.bugfix @@ -0,0 +1 @@ +give 401 error if username/password do not work for URL diff --git a/src/pip/_internal/download.py b/src/pip/_internal/download.py index 9da45eac3d8..0f6f5109fb4 100644 --- a/src/pip/_internal/download.py +++ b/src/pip/_internal/download.py @@ -48,6 +48,7 @@ try: import ssl # noqa + HAS_TLS = True except ImportError: HAS_TLS = False @@ -58,7 +59,6 @@ 'unpack_file_url', 'is_vcs_url', 'is_file_url', 'unpack_http_url', 'unpack_url'] - logger = logging.getLogger(__name__) @@ -132,7 +132,6 @@ def user_agent(): class MultiDomainBasicAuth(AuthBase): - def __init__(self, prompting=True): self.prompting = prompting self.passwords = {} @@ -197,6 +196,7 @@ def handle_401(self, resp, **kwargs): # Add our new username and password to the request req = HTTPBasicAuth(username or "", password or "")(resp.request) + req.register_hook("response", self.handle_401_again) # Send our new request new_resp = resp.connection.send(req, **kwargs) @@ -204,6 +204,14 @@ def handle_401(self, resp, **kwargs): return new_resp + def handle_401_again(self, resp, **kwargs): + if resp.status_code != 401: + return resp + + logger.warning('401 Error, Credentials not correct for %s', + resp.request.url) + return resp + def parse_credentials(self, netloc): if "@" in netloc: userinfo = netloc.rsplit("@", 1)[0] @@ -215,7 +223,6 @@ def parse_credentials(self, netloc): class LocalFSAdapter(BaseAdapter): - def send(self, request, stream=None, timeout=None, verify=None, cert=None, proxies=None): pathname = url_to_path(request.url) @@ -314,14 +321,12 @@ def delete(self, *args, **kwargs): class InsecureHTTPAdapter(HTTPAdapter): - def cert_verify(self, conn, url, verify, cert): conn.cert_reqs = 'CERT_NONE' conn.ca_certs = None class PipSession(requests.Session): - timeout = None def __init__(self, *args, **kwargs): From 2adb340b1efc2302d9e1e7d8a5c919d2b0bd5eca Mon Sep 17 00:00:00 2001 From: Kevin Date: Thu, 4 Jan 2018 16:46:35 -0600 Subject: [PATCH 2/3] removed extra newline --- src/pip/_internal/download.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pip/_internal/download.py b/src/pip/_internal/download.py index 0f6f5109fb4..6c501d5d60a 100644 --- a/src/pip/_internal/download.py +++ b/src/pip/_internal/download.py @@ -48,7 +48,6 @@ try: import ssl # noqa - HAS_TLS = True except ImportError: HAS_TLS = False From 39a27ae3c36a10cc78d2f1181b6e8848acacc2f3 Mon Sep 17 00:00:00 2001 From: Kevin Date: Tue, 6 Feb 2018 11:54:16 -0600 Subject: [PATCH 3/3] removing more newlines --- src/pip/_internal/download.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/pip/_internal/download.py b/src/pip/_internal/download.py index 6c501d5d60a..cc3a1b89499 100644 --- a/src/pip/_internal/download.py +++ b/src/pip/_internal/download.py @@ -131,6 +131,7 @@ def user_agent(): class MultiDomainBasicAuth(AuthBase): + def __init__(self, prompting=True): self.prompting = prompting self.passwords = {} @@ -222,6 +223,7 @@ def parse_credentials(self, netloc): class LocalFSAdapter(BaseAdapter): + def send(self, request, stream=None, timeout=None, verify=None, cert=None, proxies=None): pathname = url_to_path(request.url) @@ -320,12 +322,14 @@ def delete(self, *args, **kwargs): class InsecureHTTPAdapter(HTTPAdapter): + def cert_verify(self, conn, url, verify, cert): conn.cert_reqs = 'CERT_NONE' conn.ca_certs = None class PipSession(requests.Session): + timeout = None def __init__(self, *args, **kwargs):