From 36241f895cd73ec031ed68644f8c5590f68fd038 Mon Sep 17 00:00:00 2001 From: CoolCoderCarl <123qwekir2wl@gmail.com> Date: Tue, 23 Apr 2024 19:43:33 +0300 Subject: [PATCH] Better tryexception --- src/main.py | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/src/main.py b/src/main.py index d26afa5..0546c98 100644 --- a/src/main.py +++ b/src/main.py @@ -76,28 +76,29 @@ def http_requests(hosts: list): :param hosts: :return: """ - try: - for h in hosts: - try: - logging.info(f"Going to request {h}") - sleep(1) - response = requests.get(f"http://{h}", timeout=10) - logging.info(response.text) - logging.info(response.headers) - logging.info(response.ok) - - logging.info(f"{response.ok} is type {type(response.ok)}") - - if response.status_code != 200: - telegram_sender.send_alert_to_telegram( - f"Status code: {response.status_code} for this host: {h}" - ) - except requests.exceptions.SSLError as ssl_err: - telegram_sender.send_alert_to_telegram(f"{h} and {ssl_err}") - except requests.exceptions.ConnectionError as con_err: - telegram_sender.send_alert_to_telegram(f"{con_err}") - except requests.exceptions.BaseHTTPError as base_http_err: - telegram_sender.send_alert_to_telegram(f"{base_http_err}") + for h in hosts: + try: + logging.info(f"Going to request {h}") + sleep(1) + response = requests.get(f"http://{h}", timeout=10) + logging.info(response.text) + logging.info(response.headers) + logging.info(response.ok) + + logging.info(f"{response.ok} is type {type(response.ok)}") + + if response.status_code != 200: + telegram_sender.send_alert_to_telegram( + f"Status code: {response.status_code} for this host: {h}" + ) + except requests.exceptions.SSLError as ssl_err: + telegram_sender.send_alert_to_telegram(f"{h} and {ssl_err}") + except requests.exceptions.Timeout as timeout_err: + telegram_sender.send_alert_to_telegram(f"{h} and {timeout_err}") + except requests.exceptions.ConnectionError as con_err: + telegram_sender.send_alert_to_telegram(f"{h} and {con_err}") + except requests.exceptions.BaseHTTPError as base_http_err: + telegram_sender.send_alert_to_telegram(f"{h} and {base_http_err}") if __name__ == "__main__":