fix: connection check failing (#1280)
This commit is contained in:
parent
6f39dc7da1
commit
4524aca5d9
@ -115,20 +115,26 @@ def input_custom_extra_functionality(w):
|
||||
return []
|
||||
|
||||
|
||||
# Check if the workflow has access to the internet by trying to access the HEAD of specified url
|
||||
def has_internet_access(url="www.zenodo.org") -> bool:
|
||||
import http.client as http_client
|
||||
def has_internet_access(url: str = "https://www.zenodo.org", timeout: int = 3) -> bool:
|
||||
"""
|
||||
Checks if internet connection is available by sending a HEAD request
|
||||
to a reliable server like Google.
|
||||
|
||||
# based on answer and comments from
|
||||
# https://stackoverflow.com/a/29854274/11318472
|
||||
conn = http_client.HTTPConnection(url, timeout=5) # need access to zenodo anyway
|
||||
Parameters:
|
||||
- url (str): The URL to check for internet connection. Default is Google.
|
||||
- timeout (int | float): The maximum time (in seconds) the request should wait.
|
||||
|
||||
Returns:
|
||||
- bool: True if the internet is available, otherwise False.
|
||||
"""
|
||||
try:
|
||||
conn.request("HEAD", "/")
|
||||
return True
|
||||
except:
|
||||
# Send a HEAD request to avoid fetching full response
|
||||
response = requests.head(url, timeout=timeout, allow_redirects=True)
|
||||
return response.status_code == 200
|
||||
except requests.ConnectionError: # (e.g., no internet, DNS issues)
|
||||
return False
|
||||
except requests.Timeout: # (e.g., slow or no network)
|
||||
return False
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
|
||||
def solved_previous_horizon(w):
|
||||
|
Loading…
Reference in New Issue
Block a user