This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ezio.melotti
Recipients Lukáš.Němec, ezio.melotti, r.david.murray
Date 2015-03-13.18:17:36
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1426270656.82.0.0244998303981.issue23637@psf.upfronthosting.co.za>
In-reply-to
Content
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)
History
Date User Action Args
2015-03-13 18:17:36ezio.melottisetrecipients: + ezio.melotti, r.david.murray, Lukáš.Němec
2015-03-13 18:17:36ezio.melottisetmessageid: <1426270656.82.0.0244998303981.issue23637@psf.upfronthosting.co.za>
2015-03-13 18:17:36ezio.melottilinkissue23637 messages
2015-03-13 18:17:36ezio.melotticreate