import xml.etree.ElementTree as ET
from io import StringIO as sio
raw_text = '<root>can\x92t</root>'
t = ET.parse(sio(raw_text))
t = ET.parse(sio('<?xml version="1.0" encoding="UTF-8"?>' + raw_text))
t = ET.parse(sio('<?xml version="1.0" encoding="cp1252"?>' + raw_text))
t.getroot().text
import unicodedata
unicodedata.name('\u2019')
fixed_text = raw_text.decode('cp1252').encode('utf8')
t = ET.parse(sio(fixed_text))
t.getroot().text
Alternative XML parser for ElementTree to ease UTF-8 woes?