From 4856e55d6cb21f38a1ba4bdd478116fc4af2520f Mon Sep 17 00:00:00 2001 From: Luc Date: Tue, 7 Dec 2021 11:46:44 +0100 Subject: [PATCH] always good practive to catch errors Prevents printing a trace log, this except in particular catches all errors thrown by requests: https://stackoverflow.com/a/16511493 --- tubesync/healthcheck.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tubesync/healthcheck.py b/tubesync/healthcheck.py index c407674..e3635d3 100755 --- a/tubesync/healthcheck.py +++ b/tubesync/healthcheck.py @@ -18,9 +18,12 @@ TIMEOUT = 5 # Seconds def do_heatlhcheck(url): - headers = {'User-Agent': 'healthcheck'} - response = requests.get(url, headers=headers, timeout=TIMEOUT) - return response.status_code == 200 + try: + headers = {'User-Agent': 'healthcheck'} + response = requests.get(url, headers=headers, timeout=TIMEOUT) + return response.status_code == 200 + except requests.exceptions.RequestException: + return false if __name__ == '__main__':