Files
nosys_libs/app/common/network_utils.py
2026-01-25 13:55:46 +10:00

25 lines
820 B
Python

import requests
from requests.exceptions import RequestException, Timeout
def check_url(url: str, timeout: int = 10, retries: int = 3, verify_ssl: bool = False) -> bool:
"""
Check if a given URL is reachable.
Args:
url (str): The URL to check.
timeout (int): Timeout for each request in seconds.
retries (int): Number of retry attempts before failing.
verify_ssl (bool): Verify SSL.
Returns:
bool: True if the URL is reachable, False otherwise.
"""
for attempt in range(retries):
try:
response = requests.head(url, timeout=timeout, allow_redirects=True, verify=verify_ssl)
if 200 <= response.status_code < 400:
return True
except (RequestException, Timeout):
continue
return False