import fileinput from warcio.archiveiterator import ArchiveIterator import requests s = requests.Session() unknownError = "Unknown Exception" loadingError = "error loading stats" def DoStuff(uri): numIteration = 0 while numIteration < 11: r = s.get(uri) if unknownError in r.text or loadingError in r.text: print("Failed {} status code = {}".format(numIteration, r.status_code)) numIteration += 1 del r if numIteration == 11: print("Failed to get target URL") else: print("Got something") break url = "http://halo.bungie.net/Stats/Reach/FileDetails.aspx?fid=27420420" DoStuff(url)