SoFunction
Updated on 2024-11-17

Python using urllib module urlopen timeout problem solution

Started work at a new company and the subject matter of today's job was that the marketing department needed to grab some forum users' email addresses in order to send out marketing emails.

So I used a python script to execute, in front of the capture a few are no problem, and then ran into a forum, in the implementation of urlopen place is always prompted by a timeout, Baidu, because I use urllib is not urllib2, so can not be directly in the urlopen inside the timeout parameter can only be set to set the timeout of the global script! timeout

First:

Copy Code The code is as follows.

import socket

Then:

Copy Code The code is as follows.

(60)

Set the global timeout to 60s.

After that it's no big deal to execute the script again.