我如何为python的机械化设置超时值? [英] how do i set a timeout value for python's mechanize?
本文介绍了我如何为python的机械化设置超时值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何为python的机械化设置超时值?
How do i set a timeout value for python's mechanize?
推荐答案
Alex是正确的:mechanize.urlopen
带有timeout
自变量.因此,只需在浮点中插入许多秒:mechanize.urlopen('http://url/', timeout=30.0)
.
Alex is correct: mechanize.urlopen
takes a timeout
argument. Therefore, just insert a number of seconds in floating point: mechanize.urlopen('http://url/', timeout=30.0)
.
背景,来自mechanize.urlopen
的来源:
def urlopen(url, data=None, timeout=_sockettimeout._GLOBAL_DEFAULT_TIMEOUT):
...
return _opener.open(url, data, timeout)
您问的mechanize._sockettimeout._GLOBAL_DEFAULT_TIMEOUT
是什么?只是socket
模块的设置.
What is mechanize._sockettimeout._GLOBAL_DEFAULT_TIMEOUT
you ask? It's just the socket
module's setting.
import socket
try:
_GLOBAL_DEFAULT_TIMEOUT = socket._GLOBAL_DEFAULT_TIMEOUT
except AttributeError:
_GLOBAL_DEFAULT_TIMEOUT = object()
这篇关于我如何为python的机械化设置超时值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文