+ 2
About timeout in urllib
Urlib.request.urlopen(url, timeout) What will the timeout parameter returns if there is a time out? How I can do if I want to have a retry after a timeout?
1 ответ
+ 4
This should timeout for you (10.0.0.0 is unroutable):
request = urllib.request.urlopen("http://10.0.0.0", timeout=1)
Output, a traceback (exception) ending with:
urllib.error.URLError: <urlopen error timed out>
So, catch URLError (also HTTPError at this link):
https://stackoverflow.com/questions/8763451/how-to-handle-urllibs-timeout-in-JUMP_LINK__&&__python__&&__JUMP_LINK-3