Last active
January 4, 2021 10:57
-
-
Save yasinkuyu/aa505c1f4bbb4016281d7167b8fa2fc2 to your computer and use it in GitHub Desktop.
Python Check Internet Connection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#@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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.