Skip to content

Commit

Permalink
lazy-wheel: handle internal server error
Browse files Browse the repository at this point in the history
if the server returns an internal server error (500), it probably does not support negative offsets
  • Loading branch information
radoering committed Feb 26, 2024
1 parent fbffe8d commit 8f19fab
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/poetry/inspection/lazy_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,13 +611,18 @@ def _extract_content_length(
resp = e.response
code = resp.status_code if resp is not None else None
# Our initial request using a negative byte range was not supported.
if code in [codes.not_implemented, codes.method_not_allowed]:
if code in {
codes.method_not_allowed,
codes.internal_server_error,
codes.not_implemented,
}:
# pypi notably does not support negative byte ranges: see
# https://github.com/pypi/warehouse/issues/12823.
logger.debug(
"Negative byte range not supported for domain '%s': "
"using HEAD request before lazy wheel from now on",
"using HEAD request before lazy wheel from now on (code: %s)",
domain,
code,
)
# Avoid trying a negative byte range request against this domain for the
# rest of the resolve.
Expand Down
1 change: 1 addition & 0 deletions tests/inspection/test_lazy_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ def handle_request(
None,
(codes.method_not_allowed, b"Method not allowed"),
(codes.requested_range_not_satisfiable, b"Requested range not satisfiable"),
(codes.internal_server_error, b"Internal server error"),
(codes.not_implemented, b"Unsupported client range"),
(NEGATIVE_OFFSET_AS_POSITIVE, b"handle negative offset as positive"),
],
Expand Down

0 comments on commit 8f19fab

Please sign in to comment.