1 2 3 4 5 6 7 8 9 10 11 12
# Try to download image three times TRIES = 3 for x in xrange(TRIES): try: open(fname, 'w').write(urllib2.urlopen(req).read()) except IOError, ex: logging.debug(ex) pass else: break if x == TRIES: return None