Skip to content

Handle non-standard HTTP status codes#1309

Merged
woodruffw merged 4 commits intomainfrom
ww/499
Apr 17, 2026
Merged

Handle non-standard HTTP status codes#1309
woodruffw merged 4 commits intomainfrom
ww/499

Conversation

@woodruffw
Copy link
Copy Markdown
Member

@woodruffw woodruffw commented Apr 17, 2026

This addresses #1304 by turning the uncaught exception into a graceful error message and exit instead. For example, a user will now see something like:

HTTPError: 499 Unknown Status from https://...

...instead of a stack trace.

I'll also add a test for this. Done.

Closes #1304.

Signed-off-by: William Woodruff <william@astral.sh>
@woodruffw woodruffw self-assigned this Apr 17, 2026
Signed-off-by: William Woodruff <william@astral.sh>
@woodruffw
Copy link
Copy Markdown
Member Author

#1310 will unblock the CI here.

Comment thread twine/__main__.py
#
# See: <https://github.com/pypa/twine/issues/1304>
# See: <https://github.com/pypi/warehouse/issues/19713>
status_phrase = "Unknown Status"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use response.reason since we get that from the server? Why explicitly call it unknown?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use response.reason since we get that from the server? Why explicitly call it unknown?

We actually use both -- the render has the status code, phrase, and the reason. I can make that more explicit in the unit test as well, right now the reason message is invariant despite the parametrization.

(We could drop the status_phrase entirely in this case too, although that makes the diff slightly bigger for conditional rendering. Happy to change to that though.)

woodruffw and others added 2 commits April 17, 2026 16:07
Signed-off-by: William Woodruff <william@astral.sh>
@woodruffw woodruffw marked this pull request as ready for review April 17, 2026 21:17
@woodruffw woodruffw merged commit d465cb0 into main Apr 17, 2026
23 checks passed
@woodruffw woodruffw deleted the ww/499 branch April 17, 2026 22:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error during upload. ValueError: 499 is not a valid HTTPStatus

2 participants