[英]Python - urllib2 timeout
I got something below is snippet of my code 我得到的东西是我的代码片段
opener = urllib2.build_opener(redirect_handler.MyHTTPRedirectHandler())
opener.addheaders = [('Accept-encoding', 'gzip')]
fetch_timeout = 12
self.response = opener.open(url, timeout=fetch_timeout)
however, it code still waits 60~ seconds before timing out... Any clues? 然而,它的代码仍然等待60秒才超时...任何线索?
At a guess you probably need to set the socket timeout 猜测你可能需要设置套接字超时
import socket
default_timeout = 12
socket.setdefaulttimeout(default_timeout)
Which version are you using. 你使用的是哪个版本 It was added in 2.6
它是在2.6中添加的
Also the method is 方法也是
urllib2.urlopen(url[, data][, timeout])
Can you try providing 你能尝试提供吗?
self.response = opener.open(url, None, fetch_timeout)
Yeah for all others, you could still use socket module to set socket time out. 对于其他所有人,你仍然可以使用套接字模块设置套接字超时。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.