Open vfedotovs opened 1 month ago
Some proposal triage still needed:
import requests
from requests.exceptions import ConnectionError, Timeout, RequestException
import logging
log = logging.getLogger(__name__)
def fetch_data_from_url(url):
try:
response = requests.get(url, timeout=10) # Add a timeout for robustness
response.raise_for_status() # Raise an error if status code is not 200
return response.content
except ConnectionError as e:
log.error(f"Connection error occurred: {e}")
# Handle the case where the host is unreachable
return "Connection error. Host unreachable."
except Timeout:
log.error("The request timed out.")
return "Request timed out."
except RequestException as e:
log.error(f"An error occurred while making the request: {e}")
return "An error occurred while fetching data."
Affected version: 1.5.6