test: allow silencing curl connection failures on retry

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2025-12-18 07:26:40 +01:00
parent 4941b6f91a
commit ad79f6685b
+4 -2
View File
@@ -99,12 +99,13 @@ def warn(msg):
RST = "\033[0m"
print(f"{YELLOW}warn - {msg}{RST}")
def curl(url, timeout=10):
def curl(url, timeout=10, silent=False):
"""Fetch a URL and return its response body as a UTF-8 string.
Args:
url (str): The full URL to fetch.
timeout (int): Request timeout in seconds.
silent (bool): If True, suppress warning on failure (for retry scenarios).
Returns:
str | None: Response body as text, or None if the request failed.
@@ -115,5 +116,6 @@ def curl(url, timeout=10):
with urllib.request.urlopen(url, timeout=timeout) as response:
return response.read().decode('utf-8', errors='replace')
except (urllib.error.URLError, ConnectionResetError, UnicodeEncodeError) as e:
print(f"[WARN] curl: failed to fetch {url}: {e}")
if not silent:
print(f"[WARN] curl: failed to fetch {url}: {e}")
return ""