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 serhiy.storchaka
Recipients Lukáš.Němec, ezio.melotti, r.david.murray, serhiy.storchaka
Date 2015-03-13.18:48:19
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1426272499.83.0.985827448581.issue23637@psf.upfronthosting.co.za>
In-reply-to
Content
The problem is not only with the file.write(). If one of arguments is unicode (even if it doesn't contain non-ascii characters) and other argument is non-ascii string, we get this error.

>>> warnings.showwarning(u'', DeprecationWarning, 'filè.py', 10)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/serhiy/py/cpython-2.7/Lib/warnings.py", line 33, in _show_warning
    file.write(formatwarning(message, category, filename, lineno, line))
  File "/home/serhiy/py/cpython-2.7/Lib/warnings.py", line 42, in formatwarning
    s =  "%s:%s: %s: %s\n" % (filename, lineno, category.__name__, message)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 3: ordinal not in range(128)

Non-ascii file names are rare, and unicode warnings are rare, that is why this bug was not fixed before. I think it is worth to fix. It is better to output modified warning (e.g. backslashescaped) than fail without clear diagnostic.
History
Date User Action Args
2015-03-13 18:48:19serhiy.storchakasetrecipients: + serhiy.storchaka, ezio.melotti, r.david.murray, Lukáš.Němec
2015-03-13 18:48:19serhiy.storchakasetmessageid: <1426272499.83.0.985827448581.issue23637@psf.upfronthosting.co.za>
2015-03-13 18:48:19serhiy.storchakalinkissue23637 messages
2015-03-13 18:48:19serhiy.storchakacreate