Skip to content

Instantly share code, notes, and snippets.

@ARezaK
Created October 27, 2014 01:39
Show Gist options
  • Save ARezaK/fb16024682d06d7d8b67 to your computer and use it in GitHub Desktop.
Save ARezaK/fb16024682d06d7d8b67 to your computer and use it in GitHub Desktop.
Auto retrying GET using requests
def fetch_url(url, num_of_tries):
i = 0
while i < num_of_tries:
try:
content = requests.get(url, verify=False)
if content.status_code != 200:
print content.status_code
print content.text
raise Exception("Not 200")
return content
except Exception as e:
print("Exception requesting " + str(url) + " Error: " + str(e))
i += 1
time.sleep(2 * i)
return None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment