Python: handling a timeout error / socket excpetion using try catch statement

I was having a tough time downloading some 100 files continuously. It always used to timeout and then I had to start the script again. So I did the following:
while(1):
try:
fh = urllib.urlopen(www.yahoo.com)
var2=1
except:
print “THIS IS BAD1”
var2 = 0
if(var2==1):
break

Leave a Reply

Your email address will not be published. Required fields are marked *