#7 Fixing false negative results

This commit is contained in:
Patrick Müller 2021-03-20 19:37:17 +01:00
parent e0036fa352
commit 1ec878378b
2 changed files with 22 additions and 13 deletions

View File

@ -7,8 +7,12 @@ def ping(host: str) -> int:
:param host: :param host:
:return: :return:
""" """
NUMBER_OF_ATTEMPTS = 5
for iteration in range(NUMBER_OF_ATTEMPTS):
res = ping3.ping(dest_addr=host, unit='ms') res = ping3.ping(dest_addr=host, unit='ms')
if res: if res:
return int(res) return int(res)
else:
return -1 return -1

View File

@ -6,12 +6,17 @@ def ping(url: str) -> int:
:param url: The URL of the website to ping :param url: The URL of the website to ping
:return: The HTTP status code :return: The HTTP status code
""" """
NUMBER_OF_ATTEMPTS = 5
for iteration in range(NUMBER_OF_ATTEMPTS):
res = None
try: try:
res = requests.get(url) res = requests.get(url)
except: except:
return -1 pass
if res: if res:
return res.status_code return res.status_code
else:
return -1 return -1