Skip to content

Commit e2bd78d

Browse files
lineman60lineman60
authored andcommitted
Fix: HTTP Upload status codes
1 parent 0ca8b7e commit e2bd78d

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

src/poetry/publishing/uploader.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,12 +261,12 @@ def _upload_file(
261261
headers={"Content-Type": monitor.content_type},
262262
timeout=REQUESTS_TIMEOUT,
263263
)
264-
if resp is None or 200 <= resp.status_code < 300:
264+
if resp is None or 200 <= resp.status_code < 299:
265265
bar.set_format(
266266
f" - Uploading <c1>{file.name}</c1> <fg=green>%percent%%</>"
267267
)
268268
bar.finish()
269-
elif resp.status_code == 301:
269+
elif 300 <= resp.status_code < 399:
270270
if self._io.output.is_decorated():
271271
self._io.overwrite(
272272
f" - Uploading <c1>{file.name}</c1> <error>FAILED</>"
@@ -275,7 +275,9 @@ def _upload_file(
275275
"Redirects are not supported. "
276276
"Is the URL missing a trailing slash?"
277277
)
278-
elif resp.status_code == 400 and "was ever registered" in resp.text:
278+
elif (
279+
400 <= resp.status_code < 499 and "was ever registered" in resp.text
280+
):
279281
self._register(session, url)
280282
resp.raise_for_status()
281283
elif skip_existing and self._is_file_exists_error(resp):

tests/publishing/test_uploader.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,24 @@ def test_uploader_properly_handles_nonstandard_errors(
6565
assert str(e.value) == f"HTTP Error 400: Bad Request | {content}"
6666

6767

68+
@pytest.mark.parametrize(
69+
"status, body",
70+
[
71+
(308, "Permanent Redirect"),
72+
(307, "Temporary Redirect"),
73+
(304, "Not Modified"),
74+
(303, "See Other"),
75+
(302, "Found"),
76+
(301, "Moved Permanently"),
77+
(300, "Multiple Choices"),
78+
],
79+
)
80+
def test_uploader_properly_handles_redirects(
81+
http: type[httpretty.httpretty], uploader: Uploader, status: int, body: str
82+
):
83+
http.register_uri(http.POST, "https://foo.com", status=status, body=body)
84+
85+
6886
def test_uploader_properly_handles_301_redirects(
6987
http: type[httpretty.httpretty], uploader: Uploader
7088
):

0 commit comments

Comments
 (0)