Added libs
This commit is contained in:
25
app/common/network_utils.py
Normal file
25
app/common/network_utils.py
Normal file
@@ -0,0 +1,25 @@
|
||||
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
|
||||
Reference in New Issue
Block a user