diff --git a/src/pip/_internal/network/lazy_wheel.py b/src/pip/_internal/network/lazy_wheel.py index 267069bde0b..a0540575699 100644 --- a/src/pip/_internal/network/lazy_wheel.py +++ b/src/pip/_internal/network/lazy_wheel.py @@ -279,6 +279,11 @@ def _try_initial_chunk_request(self, initial_chunk_size: int) -> tuple[int, byte raise HTTPRangeRequestUnsupported( "returned complete file contents instead of range" ) + # According to MDN at + # https://developer.mozilla.org/en-US/docs/Web/HTTP/Range_requests, a 200 OK + # implies that range requests are not supported, regardless of the requested + # size. We have decided to allow servers to respond with 200 OK if the file + # size was less than or equal to requested, even if this is nonstandard. elif code != codes.partial_content: raise HTTPRangeRequestUnsupported( "did not receive partial content or ok: got code {code}" @@ -303,7 +308,7 @@ def _extract_content_length( resp = e.response code = resp.status_code # Our initial request using a negative byte range was not supported. - if code == codes.not_implemented: + if code in [codes.not_implemented, codes.method_not_allowed]: # pypi notably does not support negative byte ranges: see # https://github.com/pypi/warehouse/issues/12823. logger.debug(