我在 python 中使用 urllib2 获取 url 内容,并将其置于 python 的本机 html 解析器中。代码在我的 python 2.7.4 上运行得非常好,但是,我朋友的机器有 python 2.6.9,他的机器上面临的问题是:
Traceback (most recent call last):
File "opsview_audit.py", line 420, in <module>
check_instances_against_regex(instances)
File "opsview_audit.py", line 219, in check_instances_against_regex
attrs_being_monitored = get_host_monitoring_status(cred['url'], running_instances,
cred['user_name'], cred['pass_key'])
File "opsview_audit.py", line 112, in get_host_monitoring_status
parser.feed(result.read())
File "/usr/lib64/python2.6/HTMLParser.py", line 108, in feed
self.goahead(0)
File "/usr/lib64/python2.6/HTMLParser.py", line 148, in goahead
k = self.parse_starttag(i)
File "/usr/lib64/python2.6/HTMLParser.py", line 229, in parse_starttag
endpos = self.check_for_whole_start_tag(i)
File "/usr/lib64/python2.6/HTMLParser.py", line 304, in check_for_whole_start_tag
self.error("malformed start tag")
File "/usr/lib64/python2.6/HTMLParser.py", line 115, in error
raise HTMLParseError(message, self.getpos())
HTMLParser.HTMLParseError: malformed start tag, at line 509, column 47
可能是某些开始标记不正确,在 python 2.6.9 中被作为异常抛出,但在 2.7.4 中却没有在
这里,将 2.6.9 升级到 2.7.4 或更高版本不是一个选项。