Et.parse(xml) 'gbk' codec cant decode byte

 

import xml.etree.ElementTree as Et

Et.parse(xml) 'gbk' codec can't decode byte

 

解决办法:
把下面之前的代码
import xml.etree.ElementTree as ET
tree = ET.parse(‘C:\test.xml’)
root = tree.getroot()
改成:
import xml.etree.ElementTree as ET
f = open(‘C:\test.xml’,encoding="utf-8")
xml_text = f.read()
root = ET.fromstring(xml_text)
f.close()

你可能感兴趣的:(python)