Message238046
I think that the problem is actually with the file.write() in _show_warning().
If any of the arguments of formatwarning() are unicode, the result will be unicode, and if "file" (default sys.stderr) is opened in binary mode, Python will try to encode the unicode result with the ASCII codec and fail with a UnicodeEncodeError:
>>> warnings.showwarning(u'你好', DeprecationWarning, 'foo.py', 10)
foo.py:10: DeprecationWarning: 你好
>>> with open('err.log', 'wb') as f:
... warnings.showwarning(u'你好', DeprecationWarning, 'foo.py', 10, file=f)
...
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "/usr/lib/python2.7/warnings.py", line 30, in _show_warning
file.write(formatwarning(message, category, filename, lineno, line))
UnicodeEncodeError: 'ascii' codec can't encode characters in position 31-32: ordinal not in range(128) |
|
Date |
User |
Action |
Args |
2015-03-13 18:17:36 | ezio.melotti | set | recipients:
+ ezio.melotti, r.david.murray, Lukáš.Němec |
2015-03-13 18:17:36 | ezio.melotti | set | messageid: <1426270656.82.0.0244998303981.issue23637@psf.upfronthosting.co.za> |
2015-03-13 18:17:36 | ezio.melotti | link | issue23637 messages |
2015-03-13 18:17:36 | ezio.melotti | create | |
|