This article describes how to solve the urlopen timeout problem of the urllib module in Python. This article uses the setdefatimetimeout function in the socket module to solve the timeout problem, if you need a marketing email, refer to start work in a new company. the topic of today's work is that the marketing department needs to capture the email addresses of some forum users to send marketing emails.
So I used a python script to execute it. I caught a few of them and there was no problem. then I came across a forum where I always prompted timeout when I executed urlopen. Baidu gave me a try, because urllib is not urllib2, you cannot directly add the timeout parameter to urlopen. you can only set the timeout time of the global script.
First:
The code is as follows:
Import socket
Then:
The code is as follows:
Socket. setdefatimetimeout (60)
Set the global timeout value to 60 s.
Then there will be no major problems when executing the script.