I’m using the timeout parameter within the urllib2’s urlopen.
urllib2.urlopen('http://www.example.org', timeout=1)
How do I tell Python that if the timeout expires a custom error should be raised?
Any ideas?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There are very few cases where you want to use
except:. Doing this captures any exception, which can be hard to debug, and it captures exceptions includingSystemExitandKeyboardInterupt, which can make your program annoying to use..At the very simplest, you would catch
urllib2.URLError:The following should capture the specific error raised when the connection times out: