Why does ElementTree reject UTF-16 XML declarations with “encoding incorrect”?
问题 In Python 2.7, when passing a unicode string to ElementTree's fromstring() method that has encoding="UTF-16" in the XML declaration, I'm getting a ParseError saying that the encoding specified is incorrect: >>> from xml.etree import ElementTree >>> data = u'<?xml version="1.0" encoding="utf-16"?><root/>' >>> ElementTree.fromstring(data) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Program Files (x86)\Python 2.7\lib\xml\etree\ElementTree.py", line 1300, in