Python USES the urlopen timeout solution of the urllib module

  • 2020-04-02 14:19:34
  • OfStack

In the new company began to work, the topic of today's work is that the Marketing Department needs to grab some forum users' mail, in order to send marketing mail.

So I used a python script to execute, in front of a few are no problem, then encountered a forum, in the execution of urlopen place always prompt timeout, baidu, because I use urllib is not urllib2, so I can not directly in urlopen timeout parameter, can only be set global script timeout

First of all:


import socket

And then:


socket.setdefaulttimeout(60)

Set the global timeout time to 60s.

There are no major problems when the script is executed later.


Related articles: