HolyMackerel! Use the tools!
import urllib2, sys, socket, time, os def url_tester(url = "http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tgz"): file_name = url.split('/')[-1] u = urllib2.urlopen(url,None,1)
Print status as expected. If I unplug the Ethernet cable, I get:
Downloading: Python-2.7.3.tgz Bytes: 14,135,620 827,392 Bytes [5.85%] received sorry -- try back later
If I disconnect the cable and then connect it in less than 12 seconds, I get:
Downloading: Python-2.7.3.tgz Bytes: 14,135,620 716,800 Bytes [5.07%] received Hmmm... little issue... I'll wait a couple of seconds Hmmm... little issue... I'll wait a couple of seconds Done!
File uploaded successfully.
You can see that urllib2 supports both timeouts and reconnections. If you disconnect and remain disconnected for 3 * 4 seconds == 12 seconds, it will timeout forever and result in a fatal exception. This can be dealt with.
dawg
source share