]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-134262: Catch both URLError and ConnectionError in retries (GH-135365)...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Thu, 14 Aug 2025 19:56:42 +0000 (21:56 +0200)
committerGitHub <noreply@github.com>
Thu, 14 Aug 2025 19:56:42 +0000 (12:56 -0700)
gh-134262: Catch both URLError and ConnectionError in retries (GH-135365)
(cherry picked from commit acc20a83f4d93682e91c4992c785eaf7e3d0c69c)

Co-authored-by: Emma Smith <emma@emmatyping.dev>
PCbuild/get_external.py
Tools/build/generate_sbom.py

index 8c1155c74a642c5ef6748207a3bd6ac0cfa4f56b..a78aa6a23041adf4b3d378bc6893dab19121e749 100755 (executable)
@@ -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
index 60fb21aa2cb73093c6713a8768dde245fc33bf3c..23edd510946b4dd99f4b501412842fa57ee51b31 100644 (file)
@@ -175,7 +175,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