Skip to content

Instantly share code, notes, and snippets.

@yasinkuyu
Last active January 4, 2021 10:57
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save yasinkuyu/aa505c1f4bbb4016281d7167b8fa2fc2 to your computer and use it in GitHub Desktop.
Save yasinkuyu/aa505c1f4bbb4016281d7167b8fa2fc2 to your computer and use it in GitHub Desktop.
Python Check Internet Connection
#@yasinkuyu 08/09/2017
def check_internet():
url='http://www.google.com/'
timeout=5
try:
_ = requests.get(url, timeout=timeout)
return True
except requests.ConnectionError:
print("İnternet bağlantısı yok.")
return False
@dwonga
Copy link

dwonga commented May 21, 2018

Hi!
I tried your code and work very good, but it is important to specify that 'requests' package should be installed. For install it using python3:

pip3 install requests

Thank you for posting!

@resultuzen
Copy link

resultuzen commented Jun 3, 2018

The code above works but the "request" package needs to be installed.

If you are using "Python 3x", you should type "pip3 install requests" on the cmd screen,
If you are using "Python 2x (Default)", you should type "pip install requests" on the cmd screen.

In the latest stage: Do not forget to type "import requests" in the Python IDLE section.

########################################################################

Yukarıdaki kod işe yarıyor fakat "request" paketinin yüklü olması gerekiyor.

Eğer "Python 3x" kullanıyorsanız, cmd ekranına "pip3 install requests" yazmalı,
Eğer "Python 2x" kullanıyorsanız, cmd ekranına "pip install requests" yazmalısınız.

En son ki aşamada ise: Python IDLE kısmında "import requests" satırını yazmayı unutmayın.

@yasinkuyu
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment