Created
August 25, 2018 22:17
-
-
Save spookyahell/dcc4187d8d0782e5f03c415e13c3c780 to your computer and use it in GitHub Desktop.
python-requests: Get that nasty URL right now!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Still room for improvement ofc but this does the trick for me atm.... :)