Skip to content

Instantly share code, notes, and snippets.

@Allwin12
Created May 20, 2020 05:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Allwin12/7948a8dc80f16edda5bdc76b4a0c4ad6 to your computer and use it in GitHub Desktop.
Save Allwin12/7948a8dc80f16edda5bdc76b4a0c4ad6 to your computer and use it in GitHub Desktop.
import requests
def checkInternetRequests(url='http://www.google.com/', timeout=3):
try:
# r = requests.get(url, timeout=timeout)
r = requests.head(url, timeout=timeout)
return True
except requests.ConnectionError as ex:
print(ex)
return False
connectivity = checkInternetRequests()
if connectivity is True:
print("Connection can be established!")
else:
print("Not connected to the internet!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment