diff --git a/news/6795.bugfix b/news/6795.bugfix new file mode 100644 index 00000000000..5fb39c49e28 --- /dev/null +++ b/news/6795.bugfix @@ -0,0 +1 @@ +Allow access to an index using a URL embedded token diff --git a/src/pip/_internal/download.py b/src/pip/_internal/download.py index 8715eb5b19d..6da6830b1a9 100644 --- a/src/pip/_internal/download.py +++ b/src/pip/_internal/download.py @@ -295,7 +295,7 @@ def _get_new_credentials(self, original_url, allow_netrc=True, logger.debug("Found credentials in keyring for %s", netloc) return kr_auth - return None, None + return username, password def _get_url_and_credentials(self, original_url): """Return the credentials to use for the provided URL. @@ -314,11 +314,11 @@ def _get_url_and_credentials(self, original_url): # If nothing cached, acquire new credentials without prompting # the user (e.g. from netrc, keyring, or similar). - if username is None or password is None: + if username is None and password is None: username, password = self._get_new_credentials(original_url) - if username is not None and password is not None: - # Store the username and password + if username is not None or password is not None: + # Store any acquired credentials self.passwords[netloc] = (username, password) return url, username, password @@ -330,9 +330,9 @@ def __call__(self, req): # Set the url of the request to the url without any credentials req.url = url - if username is not None and password is not None: + if username is not None or password is not None: # Send the basic auth with this request - req = HTTPBasicAuth(username, password)(req) + req = HTTPBasicAuth(username or "", password or "")(req) # Attach a hook to handle 401 responses req.register_hook("response", self.handle_401)