{"record":{"id":"f9c54b4389114ca4","repo":"pypa/pip","slug":"could-not-install-requirement-req-because-of-htt","errorCode":null,"errorMessage":"Could not install requirement {req} because of HTTP error {exc} for URL {link}","messagePattern":"Could not install requirement (.+?) because of HTTP error (.+?) for URL (.+?)","errorType":"exception","errorClass":"InstallationError","httpStatus":null,"severity":"error","filePath":"src/pip/_internal/operations/prepare.py","lineNumber":744,"sourceCode":"                req.link = req.cached_wheel_source_link\n                link = req.link\n\n        self._ensure_link_req_src_dir(req, parallel_builds)\n\n        if link.is_existing_dir():\n            local_file = None\n        elif link.url not in self._downloaded:\n            try:\n                local_file = unpack_url(\n                    link,\n                    req.source_dir,\n                    self._download,\n                    self.verbosity,\n                    self.download_dir,\n                    hashes,\n                )\n            except NetworkConnectionError as exc:\n                raise InstallationError(\n                    f\"Could not install requirement {req} because of HTTP \"\n                    f\"error {exc} for URL {link}\"\n                )\n        else:\n            file_path = self._downloaded[link.url]\n            if hashes:\n                hashes.check_against_path(file_path)\n            local_file = File(file_path, content_type=None)\n\n        # If download_info is set, we got it from the wheel cache.\n        if req.download_info is None:\n            # Editables don't go through this function (see\n            # prepare_editable_requirement).\n            assert not req.editable\n            req.download_info = direct_url_from_link(link, req.source_dir)\n            # Make sure we have a hash in download_info. If we got it as part of the\n            # URL, it will have been verified and we can rely on it. Otherwise we\n            # compute it from the downloaded file.","sourceCodeStart":726,"sourceCodeEnd":762,"githubUrl":"https://github.com/pypa/pip/blob/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_internal/operations/prepare.py#L726-L762","documentation":"Raised in prepare_linked_requirement (prepare.py:743) when unpack_url raises NetworkConnectionError while downloading the requirement's archive/wheel. pip wraps it into an InstallationError naming the requirement, the HTTP error, and the URL so the user knows which package failed and where. It is a transient network-class failure, not a packaging problem.","triggerScenarios":"A GET to the requirement's link URL fails (DNS, TLS, timeout, proxy, 4xx/5xx, or connection reset) during the download/unpack step. Caught via 'except NetworkConnectionError as exc'.","commonSituations":"No/flaky internet, a corporate proxy or self-signed TLS interception, a private index that is down or misconfigured, rate-limiting (HTTP 429), or a temporarily unavailable CDN edge.","solutions":["Retry the install (transient network issues often resolve on retry).","Check connectivity to the URL shown in the message (curl -I) and fix proxy/TLS/DNS settings.","Configure pip's proxy and timeout: pip install --proxy http://... --timeout 60.","Switch --index-url to a reachable mirror or pre-download the wheel to a local dir and install from there."],"exampleFix":"# before\npip install pkg   # network error for URL https://...\n# after\npip install --timeout 60 --retries 5 pkg\n# or use a reachable mirror\npip install -i https://pypi.org/simple/ pkg","handlingStrategy":"retry","validationCode":"import urllib.request, ssl\n\ndef url_reachable(url: str, timeout: float = 15.0) -> bool:\n    try:\n        req = urllib.request.Request(url, method='HEAD')\n        urllib.request.urlopen(req, timeout=timeout)\n        return True\n    except Exception:\n        return False","typeGuard":"def is_reachable(url: str) -> bool:\n    return url_reachable(url)","tryCatchPattern":"import time\nfrom subprocess import run, CalledProcessError\n\nattempts = 3\nfor i in range(attempts):\n    try:\n        run([\"pip\", \"install\", \"--timeout\", \"60\", \"--retries\", \"5\", pkg], check=True)\n        break\n    except CalledProcessError:\n        if i == attempts - 1:\n            raise\n        time.sleep(2 ** i)","preventionTips":["Configure pip --timeout and --retries for flaky networks.","Verify proxy/TLS/DNS reach the index before bulk installs.","Pre-download wheels into a local directory and install offline to avoid mid-run network failures."],"tags":["network","http","download","proxy","pip"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}