{"record":{"id":"81dd61747503ec39","repo":"pypa/pip","slug":"resp-status-code-client-error-reason-for-url","errorCode":null,"errorMessage":"{resp.status_code} Client Error: {reason} for url: {resp.url}","messagePattern":"(.+?) Client Error: (.+?) for url: (.+?)","errorType":"http","errorClass":"NetworkConnectionError","httpStatus":null,"severity":"error","filePath":"src/pip/_internal/network/utils.py","lineNumber":71,"sourceCode":"        try:\n            reason = resp.reason.decode(\"utf-8\")\n        except UnicodeDecodeError:\n            reason = resp.reason.decode(\"iso-8859-1\")\n    else:\n        reason = resp.reason\n\n    if 400 <= resp.status_code < 500:\n        http_error_msg = (\n            f\"{resp.status_code} Client Error: {reason} for url: {resp.url}\"\n        )\n\n    elif 500 <= resp.status_code < 600:\n        http_error_msg = (\n            f\"{resp.status_code} Server Error: {reason} for url: {resp.url}\"\n        )\n\n    if http_error_msg:\n        raise NetworkConnectionError(http_error_msg, response=resp)\n\n\ndef response_chunks(\n    response: Response, chunk_size: int = DOWNLOAD_CHUNK_SIZE\n) -> Generator[bytes, None, None]:\n    \"\"\"Given a requests Response, provide the data chunks.\"\"\"\n    try:\n        # Special case for urllib3.\n        for chunk in response.raw.stream(\n            chunk_size,\n            # We use decode_content=False here because we don't\n            # want urllib3 to mess with the raw bytes we get\n            # from the server. If we decompress inside of\n            # urllib3 then we cannot verify the checksum\n            # because the checksum will be of the compressed\n            # file. This breakage will only occur if the\n            # server adds a Content-Encoding header, which\n            # depends on how the server was configured:","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/pypa/pip/blob/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_internal/network/utils.py#L53-L89","documentation":"Raised as NetworkConnectionError by raise_for_status when an HTTP response carries a 4xx (Client Error) or 5xx (Server Error) status code. The message format is '{status_code} Client Error: {reason} for url: {url}' (and the Server Error variant for 5xx). The original requests Response is attached as .response so callers can inspect status, headers, and body.","triggerScenarios":"pip performs an HTTP GET (index simple page, JSON API, file download) and the server replies with 401/403/404/500/502/503 etc.; raise_for_status converts that into an exception.","commonSituations":"Wrong package name or index URL (404); private index requiring auth (401/403); index server outage or gateway error (500/502/503); rate limiting; expired credentials.","solutions":["Verify the package name and the configured index URL (pip config list; pip install -v).","Provide credentials if the status is 401/403 (auth in URL, keyring, or --index-url with creds).","Retry on transient 5xx errors; switch to an alternate mirror if persistent.","Check pip.conf for a stale/mistyped index-url or extra-index-url."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"from pip._internal.exceptions import NetworkConnectionError\n\ntry:\n    resp = session.get(url)\n    raise_for_status(resp)\nexcept NetworkConnectionError as e:\n    status = e.response.status_code if e.response is not None else None\n    if status in (401, 403):\n        # supply credentials and retry\n        ...\n    elif status and 500 <= status < 600:\n        # transient server error, retry with backoff\n        ...\n    else:\n        raise","preventionTips":["Validate package names and index URLs before installing.","Configure authentication for private indexes up front.","Retry transient 5xx with backoff; switch mirrors on persistent 4xx."],"tags":["network","http","status-code","client-error"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}