File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 99import sys
1010import typing
1111import urllib .request
12+ import urllib .error
1213from pathlib import Path , PurePosixPath , PureWindowsPath
1314
1415CPYTHON_ROOT_DIR = Path (__file__ ).parent .parent .parent
@@ -161,6 +162,21 @@ def get_externals() -> list[str]:
161162 return externals
162163
163164
165+ def download_with_retries (download_location , retries = 5 ):
166+ """Download a file with exponential backoff retry."""
167+ attempt = 0
168+ while attempt < retries :
169+ attempt += 1
170+ try :
171+ resp = urllib .request .urlopen (download_location )
172+ except urllib .error .URLError as ex :
173+ if attempt == retries :
174+ raise ex
175+ time .sleep (2 ** attempt )
176+ else :
177+ return resp
178+
179+
164180def check_sbom_packages (sbom_data : dict [str , typing .Any ]) -> None :
165181 """Make a bunch of assertions about the SBOM package data to ensure it's consistent."""
166182
@@ -175,7 +191,7 @@ def check_sbom_packages(sbom_data: dict[str, typing.Any]) -> None:
175191 # and that the download URL is valid.
176192 if "checksums" not in package or "CI" in os .environ :
177193 download_location = package ["downloadLocation" ]
178- resp = urllib . request . urlopen (download_location )
194+ resp = download_with_retries (download_location )
179195 error_if (resp .status != 200 , f"Couldn't access URL: { download_location } '" )
180196
181197 package ["checksums" ] = [{
You can’t perform that action at this time.
0 commit comments