mirror of
https://github.com/python/cpython.git
synced 2025-12-31 04:23:37 +00:00
[3.14] gh-134262: Catch both URLError and ConnectionError in retries (GH-135365) (#135611)
Co-authored-by: Emma Smith <emma@emmatyping.dev>
This commit is contained in:
parent
3233cff84e
commit
91d9e9e64e
2 changed files with 5 additions and 4 deletions
|
|
@ -5,8 +5,9 @@
|
|||
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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue