From 2796bd1c2410a35e5028dedc2b301de6a91d72cb Mon Sep 17 00:00:00 2001 From: Emma Harper Smith Date: Tue, 10 Jun 2025 13:27:09 -0700 Subject: [PATCH 1/2] Catch both URLError and ConnectionError in retries --- PCbuild/get_external.py | 3 ++- Tools/build/generate_sbom.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/PCbuild/get_external.py b/PCbuild/get_external.py index 8c1155c74a642c..7b4de0250b7f33 100755 --- a/PCbuild/get_external.py +++ b/PCbuild/get_external.py @@ -5,6 +5,7 @@ import pathlib import sys import time +import urllib.error import zipfile from urllib.request import urlretrieve @@ -19,7 +20,7 @@ def retrieve_with_retries(download_location, output_path, reporthook, 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 df52f8de762a01..968397728b2f67 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 From ffd6b953986b6e119c7d05b992c78229cf95182c Mon Sep 17 00:00:00 2001 From: Emma Harper Smith Date: Fri, 13 Jun 2025 13:15:18 -0400 Subject: [PATCH 2/2] Unify imports --- PCbuild/get_external.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PCbuild/get_external.py b/PCbuild/get_external.py index 7b4de0250b7f33..a78aa6a23041ad 100755 --- a/PCbuild/get_external.py +++ b/PCbuild/get_external.py @@ -6,8 +6,8 @@ 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, @@ -15,7 +15,7 @@ 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,