Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 执行ElementTree脚本时出现问题_Python_Xml_Elementtree - Fatal编程技术网

Python 执行ElementTree脚本时出现问题

Python 执行ElementTree脚本时出现问题,python,xml,elementtree,Python,Xml,Elementtree,我有一个二氧化碳监测设备,我有一个关于解析该设备输出的xml流的问题。当我在命令提示符下逐行运行代码时,我没有遇到任何问题,但当我尝试运行脚本时,会出现“格式不正确(无效令牌)”错误 来自设备的xml如下所示: <li820><data><celltemp>5.1411118e1</celltemp<cellpres>8.4122142e1</cellpres><co2>3.8320891e2</co2>&

我有一个二氧化碳监测设备,我有一个关于解析该设备输出的xml流的问题。当我在命令提示符下逐行运行代码时,我没有遇到任何问题,但当我尝试运行脚本时,会出现“格式不正确(无效令牌)”错误

来自设备的xml如下所示:

<li820><data><celltemp>5.1411118e1</celltemp<cellpres>8.4122142e1</cellpres><co2>3.8320891e2</co2><co2abs>6.2126092e-2</co2abs><ivolt>1.7133789e1</ivolt><raw>3246069,3390159</raw></data></li820>
正如我上面所说的,我可以逐行运行这个函数,它返回一个值,比如383.21,很好。但是,当我尝试运行一个>Python Port_Sniffer.py命令时,它返回:

Traceback (most recent call last): File "Port_Sniffer.py", line 23, in <module>
datastream = ET.fromstring(readout)  File "<string>", line 124, in XML 
cElementTree.ParseError: not well-formed (invalid token): line 1, column 4
Traceback(最近一次调用last):文件“Port_Sniffer.py”,第23行,在
datastream=ET.fromstring(读出)文件“”,第124行,XML格式
cElementTree.ParseError:格式不正确(无效令牌):第1行第4列

我希望能够定期运行这个脚本,所以如果有人知道如何修复这个错误,那就太棒了

它可能有助于简单地打印出要读取的内容、调试等。XML中一个元素的结束标记缺少一个直角括号<代码>
Traceback (most recent call last): File "Port_Sniffer.py", line 23, in <module>
datastream = ET.fromstring(readout)  File "<string>", line 124, in XML 
cElementTree.ParseError: not well-formed (invalid token): line 1, column 4