Serhiy Storchaka added the comment: format_exception_only() produces a Unicode string for SyntaxError with Unicode source line.
>>> traceback.format_exception_only(SyntaxError, SyntaxError('failed', >>> ('<tokenize>', 7, 2, u' // test'))) [' File "<tokenize>", line 7\n', u' // test\n', ' ^\n', 'SyntaxError: failed\n'] But io.BytesIO() accepts only binary strings. The similar issue is caused by Unicode file name: >>> traceback.format_exception_only(SyntaxError, SyntaxError('failed', >>> (u'<tokenize>', 7, 2, ' // test'))) [u' File "<tokenize>", line 7\n', ' // test\n', ' ^\n', 'SyntaxError: failed\n'] But Unicode error message doesn't produce Unicode output: >>> traceback.format_exception_only(SyntaxError, SyntaxError(u'failed', >>> ('<tokenize>', 7, 2, ' // test'))) [' File "<tokenize>", line 7\n', ' // test\n', ' ^\n', 'SyntaxError: failed\n'] How you got a Unicode source line in SyntaxError? ---------- components: +Library (Lib), Unicode nosy: +ezio.melotti, haypo, serhiy.storchaka type: -> behavior _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue29809> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com