0

I'm trying to access the XML elements using ElementTree in Python 3.7. XML entry tag in the file my_file.xml is of the format:

<?xml version="1.0" encoding="utf-16"?>

When I try to parse the XML using the below method,

>>import xml.etree.ElementTree as ET
>>file_content = ET.parse('my_file.xml')

I keep getting the error as:

xml.etree.ElementTree.ParseError: encoding specified in XML declaration is incorrect

What could be the reason for this?

Bogota
  • 401
  • 4
  • 15
  • 2
    Does this answer your question? [Why does ElementTree reject UTF-16 XML declarations with "encoding incorrect"?](https://stackoverflow.com/questions/24045892/why-does-elementtree-reject-utf-16-xml-declarations-with-encoding-incorrect) – Amit Nanaware Apr 23 '21 at 07:27
  • Oh yes, it does. – Bogota Apr 23 '21 at 07:31

0 Answers0