[issue9692] UnicodeDecodeError in ElementTree.tostring()

Ulrich Seidl report at bugs.python.org
Tue Jan 11 14:33:55 CET 2011

Ulrich Seidl <Ulrich.Seidl at muneda.com> added the comment:

I would suggest adding an additional except branch to (at least) the following functions of ElementTree.py:
* _encode,
* _escape_attrib, and
* _escape_cdata 

The except branch could look like:

except (UnicodeDecodeError):
    return text.decode( encoding ).encode( encoding, "xmlcharrefreplace")


Python tracker <report at bugs.python.org>

More information about the Python-bugs-list mailing list