Python 2.6 XML解析器断言错误
我在用python解析zenoss服务器上的XML文档时出错。我如何避开错误/修复错误 代码如下:Python 2.6 XML解析器断言错误,python,xml,python-2.6,xml.etree,Python,Xml,Python 2.6,Xml.etree,我在用python解析zenoss服务器上的XML文档时出错。我如何避开错误/修复错误 代码如下: import xml.etree.ElementTree as ET tree = ET.parse('/root/Dropbox/Public/N8800Space.xml') root = tree.getroot() 以下是XML文件: <?xml version="1.0" encoding="utf-8"?> <root> <item>
import xml.etree.ElementTree as ET
tree = ET.parse('/root/Dropbox/Public/N8800Space.xml')
root = tree.getroot()
以下是XML文件:
<?xml version="1.0" encoding="utf-8"?>
<root>
<item>
<value>125</value>
<label>Used</label>
<colour>FFFF10AA</colour>
</item>
<item>
<value>125</value>
<label>Free</label>
<colour>FF0010AA</colour>
</item>
</root>
输出:
Traceback (most recent call last):
File "geckoBoard.py", line 1, in <module>
from lxml import etree
File "lxml.etree.pyx", line 123, in init lxml.etree (src/lxml/lxml.etree.c:156336)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)
回溯(最近一次呼叫最后一次):
文件“geckoBoard.py”,第1行,在
从lxml导入etree
文件“lxml.etree.pyx”,第123行,在init lxml.etree(src/lxml/lxml.etree.c:156336)中
UnicodeEncodeError:“ascii”编解码器无法对位置0-1中的字符进行编码:序号不在范围内(128)
您确定发布了整个xml文件吗?我检查了源代码,似乎模块认为您的结束标记不匹配。但是我可以在我的机器上很好地运行xml(fromstring)。
from lxml import etree
doc = etree.parse('/root/Dropbox/Public/N8800Space.xml')
root = doc.getroot()
Traceback (most recent call last):
File "geckoBoard.py", line 1, in <module>
from lxml import etree
File "lxml.etree.pyx", line 123, in init lxml.etree (src/lxml/lxml.etree.c:156336)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)