From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Tue, 17 Jun 2025 12:16:17 +0000 (+0200) Subject: [3.14] gh-134262: Catch both URLError and ConnectionError in retries (GH-135365)... X-Git-Tag: v3.14.0b3~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=91d9e9e64e3e1c62e9a324e246a2e350f7bc9ca4;p=thirdparty%2FPython%2Fcpython.git [3.14] gh-134262: Catch both URLError and ConnectionError in retries (GH-135365) (#135611) Co-authored-by: Emma Smith --- diff --git a/PCbuild/get_external.py b/PCbuild/get_external.py index 8c1155c74a64..a78aa6a23041 100755 --- a/PCbuild/get_external.py +++ b/PCbuild/get_external.py @@ -5,8 +5,9 @@ import os import pathlib import sys import time +import urllib.error +import urllib.request import zipfile -from urllib.request import urlretrieve def retrieve_with_retries(download_location, output_path, reporthook, @@ -14,12 +15,12 @@ def retrieve_with_retries(download_location, output_path, reporthook, """Download a file with exponential backoff retry and save to disk.""" for attempt in range(max_retries + 1): try: - resp = urlretrieve( + resp = urllib.request.urlretrieve( download_location, output_path, reporthook=reporthook, ) - except ConnectionError as ex: + except (urllib.error.URLError, ConnectionError) as ex: if attempt == max_retries: msg = f"Download from {download_location} failed." raise OSError(msg) from ex diff --git a/Tools/build/generate_sbom.py b/Tools/build/generate_sbom.py index df52f8de762a..968397728b2f 100644 --- a/Tools/build/generate_sbom.py +++ b/Tools/build/generate_sbom.py @@ -172,7 +172,7 @@ def download_with_retries(download_location: str, for attempt in range(max_retries + 1): try: resp = urllib.request.urlopen(download_location) - except urllib.error.URLError as ex: + except (urllib.error.URLError, ConnectionError) as ex: if attempt == max_retries: msg = f"Download from {download_location} failed." raise OSError(msg) from ex