From 7dc92d36ace758b6a6037bfd7025cd8e1e217e96 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Mon, 17 Mar 2025 11:35:14 -0500 Subject: [PATCH 1/2] Display the number of retries --- pythonbuild/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pythonbuild/utils.py b/pythonbuild/utils.py index 14d9a474..c63337db 100644 --- a/pythonbuild/utils.py +++ b/pythonbuild/utils.py @@ -310,7 +310,7 @@ def download_to_path(url: str, path: pathlib.Path, size: int, sha256: str): print(f"urllib error on {url}; retrying: {e}") time.sleep(2**attempt) else: - raise Exception("download failed after multiple retries: %s" % url) + raise Exception(f"download failed after {attempt} retries: {url}") tmp.rename(path) print("successfully downloaded %s" % url) From 14c8640315a8a7f8dc7a7766a9503c2aa84930e3 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Mon, 17 Mar 2025 11:38:43 -0500 Subject: [PATCH 2/2] Increase sleep during possible rate limit errors in downloads --- pythonbuild/utils.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pythonbuild/utils.py b/pythonbuild/utils.py index c63337db..20e40ed3 100644 --- a/pythonbuild/utils.py +++ b/pythonbuild/utils.py @@ -307,8 +307,12 @@ def download_to_path(url: str, path: pathlib.Path, size: int, sha256: str): print(f"HTTP exception on {url}; retrying: {e}") time.sleep(2**attempt) except urllib.error.URLError as e: - print(f"urllib error on {url}; retrying: {e}") - time.sleep(2**attempt) + if e.errno in {403, 429}: + print(f"possible rate limit error on {url}; retrying: {e}") + time.sleep(2 ** (attempt + 2)) + else: + print(f"urllib error on {url}; retrying: {e}") + time.sleep(2**attempt) else: raise Exception(f"download failed after {attempt} retries: {url}")