The title of this question is the same as this one, but my problem is different.
I have data read from a tar.gz archive using tarfile.TarFile.extractfile() and stored in an xml.etree.ElementTree.Element. The data is utf-8 encoded.
When I attempt to use xml.etree.ElementTree.ElementTree.write() to put it in a file, I get this:
Traceback (most recent call last):
File "../python/GetDoc.py", line 150, in <module>
ET.ElementTree(elements).write(args.outfile, encoding="us-ascii", method="text")
File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 815, in write
_serialize_text(write, self._root, encoding)
File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 1007, in _serialize_text
write(part.encode(encoding))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 10: ordinal not in range(128)