Skip to content

Instantly share code, notes, and snippets.

@spookyahell
Created August 25, 2018 22:17
Show Gist options
  • Save spookyahell/dcc4187d8d0782e5f03c415e13c3c780 to your computer and use it in GitHub Desktop.
Save spookyahell/dcc4187d8d0782e5f03c415e13c3c780 to your computer and use it in GitHub Desktop.
python-requests: Get that nasty URL right now!
def GTDU(u, timeout, RT = 0, CE = 0, headers = None):
try:
r = requests.get(u, timeout = timeout, headers = headers)
return r
except requests.exceptions.ReadTimeout:
RT += 1
if RT<5:
r = GTDU(u, timeout, RT = RT, CE = CE, headers = headers)
return r
else:
return 'ReadTimeout'
except requests.exceptions.ConnectionError:
CE += 1
if RT<5:
r = GTDU(u, timeout, RT = RT, CE = CE, headers = headers)
return r
else:
return 'ConnErr'
@spookyahell
Copy link
Author

Still room for improvement ofc but this does the trick for me atm.... :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment