Python - urllib2 超时 [英] Python - urllib2 timeout
本文介绍了Python - urllib2 超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面是我的代码片段
opener = urllib2.build_opener(redirect_handler.MyHTTPRedirectHandler())
opener.addheaders = [('Accept-encoding', 'gzip')]
fetch_timeout = 12
self.response = opener.open(url, timeout=fetch_timeout)
然而,它的代码在超时之前仍然等待 60~ 秒...有什么线索吗?
however, it code still waits 60~ seconds before timing out... Any clues?
推荐答案
猜测您可能需要设置套接字超时
At a guess you probably need to set the socket timeout
import socket
default_timeout = 12
socket.setdefaulttimeout(default_timeout)
这篇关于Python - urllib2 超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文