Skip to content

Commit a63d057

Browse files
emmatypingmiss-islington
authored andcommitted
pythongh-134262: Catch both URLError and ConnectionError in retries (pythonGH-135365)
(cherry picked from commit acc20a8) Co-authored-by: Emma Smith <emma@emmatyping.dev>
1 parent 3233cff commit a63d057

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

PCbuild/get_external.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,22 @@
55
import pathlib
66
import sys
77
import time
8+
import urllib.error
9+
import urllib.request
810
import zipfile
9-
from urllib.request import urlretrieve
1011

1112

1213
def retrieve_with_retries(download_location, output_path, reporthook,
1314
max_retries=7):
1415
"""Download a file with exponential backoff retry and save to disk."""
1516
for attempt in range(max_retries + 1):
1617
try:
17-
resp = urlretrieve(
18+
resp = urllib.request.urlretrieve(
1819
download_location,
1920
output_path,
2021
reporthook=reporthook,
2122
)
22-
except ConnectionError as ex:
23+
except (urllib.error.URLError, ConnectionError) as ex:
2324
if attempt == max_retries:
2425
msg = f"Download from {download_location} failed."
2526
raise OSError(msg) from ex

Tools/build/generate_sbom.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def download_with_retries(download_location: str,
172172
for attempt in range(max_retries + 1):
173173
try:
174174
resp = urllib.request.urlopen(download_location)
175-
except urllib.error.URLError as ex:
175+
except (urllib.error.URLError, ConnectionError) as ex:
176176
if attempt == max_retries:
177177
msg = f"Download from {download_location} failed."
178178
raise OSError(msg) from ex

0 commit comments

Comments
 (0)