{"id":"5ac5d67bc3f0a033","repo":"python-poetry/poetry","slug":"http-error-e-response-status-code-e-response-r","errorCode":null,"errorMessage":"HTTP Error {e.response.status_code}: {e.response.reason} | {e.response.content!r}","messagePattern":"HTTP Error (.+?): (.+?) \\| (.+?)","errorType":"http","errorClass":"UploadError","httpStatus":null,"severity":"error","filePath":"src/poetry/publishing/uploader.py","lineNumber":290,"sourceCode":"                        f\" - Uploading <c1>{file.name}</c1> <warning>File exists.\"\n                        \" Skipping</>\"\n                    )\n                    bar.display()\n                else:\n                    resp.raise_for_status()\n\n            except requests.RequestException as e:\n                if self._io.output.is_decorated():\n                    self._io.overwrite(\n                        f\" - Uploading <c1>{file.name}</c1> <error>FAILED</>\"\n                    )\n\n                if e.response is not None:\n                    message = (\n                        f\"HTTP Error {e.response.status_code}: \"\n                        f\"{e.response.reason} | {e.response.content!r}\"\n                    )\n                    raise UploadError(message) from e\n\n                raise UploadError(\"Error connecting to repository\") from e\n\n            finally:\n                self._io.write_line(\"\")\n\n    def _register(self, session: requests.Session, url: str) -> requests.Response:\n        \"\"\"\n        Register a package to a repository.\n        \"\"\"\n        data = self.post_data(self.files[0])\n        data.update({\":action\": \"submit\", \"protocol_version\": \"1\"})\n\n        data_to_send = self._prepare_data(data)\n        encoder = MultipartEncoder(data_to_send)\n        resp = session.post(\n            url,\n            data=encoder,","sourceCodeStart":272,"sourceCodeEnd":308,"githubUrl":"https://github.com/python-poetry/poetry/blob/92b74dcfe348d0e01e14d40d6c1fa47a4ee04a54/src/poetry/publishing/uploader.py#L272-L308","documentation":"Raised by Uploader._upload_file() inside the requests.RequestException handler when the exception carries a response (e.g. HTTPError from raise_for_status). It wraps status code, reason phrase, and raw response body into an UploadError so the caller sees a single error type with diagnostic detail.","triggerScenarios":"The repository server returns a non-success status that is not a handled case (redirect, file-exists, ever-registered). resp.raise_for_status() raises HTTPError which is caught as RequestException with .response set; the handler re-throws UploadError with the formatted message.","commonSituations":"403 Forbidden (bad token/credentials), 404 (wrong upload URL), 413 (file too large), 500/502/503 (server error), 400 with an unrelated error body, rate limiting (429).","solutions":["Read the embedded status code and response body — they identify the server-side problem.","401/403: verify credentials/token (`poetry config http-basic.<name>` or set the API token correctly).","4xx with a message about file size/name: fix the package metadata or reduce size.","5xx/429: retry after a short delay; check the index's status page.","Confirm the upload URL is correct and the package name is registered on the index."],"exampleFix":"// before: 403 due to invalid token\nUploadError: HTTP Error 403: Forbidden | b'Invalid or non-existent authentication...'\n\n// after\n$ poetry config pypi-token.pypi pypi-xxxxxxxxxxxx\n$ poetry publish","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"from poetry.publishing.uploader import UploadError\n\ntry:\n    publisher.publish(...)\nexcept UploadError as e:\n    msg = str(e)\n    if msg.startswith(\"HTTP Error\"):\n        status = int(msg.split()[2].rstrip(\":\"))\n        # branch on status: 401/403 -> creds, 429 -> retry, 5xx -> retry\n        ...","preventionTips":["Validate credentials/tokens before publishing (`poetry config pypi-token.<name>`).","Confirm the upload URL and package registration on the index.","Inspect the response body embedded in the error to diagnose server-side rejection.","For 5xx/429, retry with exponential backoff."],"tags":["publishing","network","http","authentication"],"analyzedSha":"92b74dcfe348d0e01e14d40d6c1fa47a4ee04a54","analyzedAt":"2026-08-04T20:33:34.072Z","schemaVersion":2}