当前位置: 技术问答>linux和unix
python 的httplib.HTTPSConnection(),这个怎么设置超时时间?
来源: 互联网 发布时间:2016-06-25
本文导语: import httplib conn=httplib.HTTPSConnection(ipaddr) conn.request(method,path) rd=conn.getresponse() print rd conn.close() 这段代码,请问一下,比如ipaddr所在的设备本身就是不在线的,我想自己设置个默认时间,超过这个时间我就认为他不在...
import httplib
conn=httplib.HTTPSConnection(ipaddr)
conn.request(method,path)
rd=conn.getresponse()
print rd
conn.close()
这段代码,请问一下,比如ipaddr所在的设备本身就是不在线的,我想自己设置个默认时间,超过这个时间我就认为他不在线了。
应该在哪里设置?我查了一下他的源码里,并没有timeout这个参数可传。哪位前辈了解麻烦给个示例。谢谢了。
conn=httplib.HTTPSConnection(ipaddr)
conn.request(method,path)
rd=conn.getresponse()
print rd
conn.close()
这段代码,请问一下,比如ipaddr所在的设备本身就是不在线的,我想自己设置个默认时间,超过这个时间我就认为他不在线了。
应该在哪里设置?我查了一下他的源码里,并没有timeout这个参数可传。哪位前辈了解麻烦给个示例。谢谢了。
|
# timeout in seconds
# this call to urllib2.urlopen now uses the default timeout
# we have set in the socket module
import socket
timeout = 120 # in seconds
socket.setdefaulttimeout(timeout)
# this call to urllib2.urlopen now uses the default timeout
# we have set in the socket module
import socket
timeout = 120 # in seconds
socket.setdefaulttimeout(timeout)
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。