Skip to content

Commit 32cd700

Browse files
Update internet_connection_check.py
1 parent 806f49c commit 32cd700

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
import requests
2+
from requests.exceptions import ConnectionError
23

34
def internet_connection_test():
45
url = 'https://www.google.com/'
56
print(f'Attempting to connect to {url} to determine internet connection status.')
67

78
try:
8-
requests.get(url, timeout = 10)
9+
print(url)
10+
resp = requests.get(url, timeout = 10)
11+
resp.text
12+
resp.status_code
913
print(f'Connection to {url} was successful.')
1014
return True
11-
except:
15+
except ConnectionError as e:
1216
requests.ConnectionError
1317
print(f'Failed to connect to {url}.')
1418
return False
15-
19+
except:
20+
print(f'Failed with unparsed reason.')
21+
return False
22+
1623
internet_connection_test()

0 commit comments

Comments
 (0)