replace urllib.urlretrieve with urllib2.urlopen and some sanity checking