【发布时间】:2014-11-04 23:06:52
【问题描述】:
我遇到了mechanize 的timeout 功能的问题。在大多数页面上,它都能完美运行,如果 URL 在合理的时间内无法加载,则会引发错误:urllib2.URLError: <urlopen error timed out>。但是,在某些页面上,定时器不工作,程序甚至对键盘中断也没有响应。这是发生这种情况的示例页面:
import mechanize
url = 'https://web.archive.org/web/20141104183547/http://www.dallasnews.com/'
br = mechanize.Browser()
br.set_handle_robots(False)
br.addheaders = [('User-agent', 'Firefox')]
html = br.open(url, timeout=0.01).read() #hangs on this page, timeout set extremely low to trigger timeout on all pages for debugging
首先,对于这个特定的 URL,这个脚本是否会为其他人挂起?其次,可能出了什么问题/我该如何调试?
【问题讨论】: