[issue29809] TypeError in traceback.print_exc - unicode does not have the buffer interface

STINNER Victor report at bugs.python.org
Tue Mar 14 11:41:46 EDT 2017


STINNER Victor added the comment:

sys.stderr.write() accepts Unicode (encoded to sys.stderr.encoding), whereas io.BytesIO.write() requires bytes:

>>> import sys; sys.stderr.write(u'\xe9\n')
é

>>> import io; io.BytesIO().write(u'\xe9\n')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'unicode' does not have the buffer interface


You should write an helper function (class with a write method) encoding Unicode strings.


> The same test runs without error on Python 3.

Yeah, it's now time to upgrade to Python 3 ;-)

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue29809>
_______________________________________


More information about the Python-bugs-list mailing list