I've got a Li-Cor 820 carbon dioxide monitoring device, and I have a question about parsing the xml stream that the device outputs. When I run my code line by line in the command prompt, I do not encounter any problems, but when I attempt to run my script, I get a "not well-formed(invalid token)" error.
The xml coming off the device looks like this:
<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>
Here is my code for Port_Sniffer.py:
import serial
import xml.etree.cElementTree as ET
ser = serial.Serial(0)
readout = ser.readline()
datastream = ET.fromstring(readout)
tree = ET.ElementTree(datastream)
co2val = 0
for elem in tree.iter('co2'):
co2val = round(decimal.Decimal(float(elem.text)), 2)
print co2val
So as I said above, I can run this line-by-line and it returns a value, eg. 383.21, just fine. But when I attempt to run a >Python Port_Sniffer.py command, it returns with:
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
I would like to be able to run this script on a recurring basis, so if anyone knows how to fix this error that would be awesome!