{"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/d7d0d0a39494e28ec1c407bd0680e4a4d1067791/src/pip/_internal/operations/prepare.py#L726-L762","documentation":"Raised as InstallationError when downloading and unpacking a requirement fails with a NetworkConnectionError. At prepare.py:743-747, _prepare_linked_requirement wraps the unpack_url() call in try/except NetworkConnectionError and re-raises a user-facing InstallationError naming the requirement and the URL. This surfaces transport-layer failures with full requirement context.","triggerScenarios":"Any network failure while fetching a requirement's archive: DNS error, connection refused/reset, TLS failure, timeout, proxy error, or an HTTP 4xx/5xx from raise_for_status. The original NetworkConnectionError (and its message) is embedded in the InstallationError text.","commonSituations":"Intermittent network during dependency resolution, a private index going down mid-resolve, a flaky CDN, corporate firewall blocking the file host, or a mistyped --index-url/--find-links URL.","solutions":["Inspect the embedded network error and the URL in the message to identify the failing host.","Increase resilience: pip install --retries 5 --timeout 60 -r requirements.txt.","Verify connectivity to the file host (curl -I <url>) and fix --index-url/--find-links if wrong.","Retry once transient issues clear; for persistent failures, switch to a reachable mirror or pre-download the artifact."],"exampleFix":"# before\npip install -r requirements.txt  # -> Could not install req ... HTTP error ... for URL https://broken/files\n\n# after (reachable mirror + retries)\npip install --retries 5 --timeout 60 \\\n  --index-url https://pypi.org/simple/ -r requirements.txt","handlingStrategy":"retry","validationCode":"import socket, urllib.parse\nurl = str(link)\nhost = urllib.parse.urlparse(url).hostname\nif host:\n    try:\n        socket.getaddrinfo(host, 443)\n    except socket.gaierror as e:\n        raise SystemExit(f\"index/file host {host} not resolvable: {e}\")","typeGuard":null,"tryCatchPattern":"from pip._internal.exceptions import InstallationError\nfor attempt in range(3):\n    try:\n        preparer.prepare_linked_requirement(req)\n        break\n    except InstallationError as e:\n        if \"HTTP error\" not in str(e) or attempt == 2:\n            raise\n        logger.warning(\"transient HTTP failure (%s), retry %d\", e, attempt + 1)","preventionTips":["Set --retries and --timeout generously in CI pip invocations.","Pre-validate reachability of index/find-links hosts before resolving.","Keep a local wheel cache (--find-links) for offline resilience."],"tags":["network","download","http-error","connection","install"],"analyzedSha":"d7d0d0a39494e28ec1c407bd0680e4a4d1067791","analyzedAt":"2026-08-04T20:55:04.259Z","schemaVersion":2}