I am trying to learn python. This a script I wrote to check internet connection
import os
import urllib2
from time import sleep
REMOTE_SERVER = \"www.google.co.u
Since you haven't imported socket
, your reference to socket.gethostbyname
will fail with a NameError. But you're catching and silencing every single exception in your try/except block, including that very error. You should never ever do a blank except in the first place, and especially never just to have pass
.
Remove that try/except, or limit it to exceptions you know you can handle.
Basically, never do this:
try:
something()
except:
pass
Which is the Python equivalent of the good'ol Visual Basic anti-pattern, if you recall:
On Error Resume Next
Leading to unmaintainable and impossible to debug code. Simply because when a problem arises, you don't know what happened (and you don't even know that there is any problem at all).
In your particular case, I suggest you remove the try/except block so that you can know which exception is raised in the traceback. Then, you'll be able to fix it.