From 2939ca53f09a778500632deacfc63ff17f1ec3d8 Mon Sep 17 00:00:00 2001 From: Jean-Martin Archer Date: Fri, 5 Nov 2021 16:10:16 -0700 Subject: [PATCH] pypi, retry when receiving a 200 with empty body For some reason, pypi is returning a 200 and an empty body from time to time. The next time you query the same endpoint it returns a proper JSON object. This is not fixing a bug in poetry, but working around the issue. --- poetry/repositories/pypi_repository.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/poetry/repositories/pypi_repository.py b/poetry/repositories/pypi_repository.py index 79199ff12fd..0dfcc639220 100755 --- a/poetry/repositories/pypi_repository.py +++ b/poetry/repositories/pypi_repository.py @@ -313,6 +313,9 @@ def _get_release_info(self, name, version): # type: (str, str) -> dict def _get(self, endpoint): # type: (str) -> Union[dict, None] try: json_response = self.session.get(self._base_url + endpoint) + if json_response.status_code == 200 and json_response.content == b"": + logger.warn("Got empty response from PyPI for %s. Retrying...", endpoint) + json_response = self.session.get(self._base_url + endpoint) except requests.exceptions.TooManyRedirects: # Cache control redirect loop. # We try to remove the cache and try again