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
This commit is contained in:
Luc 2021-12-07 11:46:44 +01:00
parent fe7baed7f9
commit 4856e55d6c
1 changed files with 6 additions and 3 deletions

View File

@ -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__':