homepage

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 Piotr.Czachur
Recipients Piotr.Czachur
Date 2011年06月15日.13:41:59
SpamBayes Score 1.3334782e-08
Marked as misclassified No
Message-id <1308145321.11.0.0545021570949.issue12339@psf.upfronthosting.co.za>
In-reply-to
Content
If I want my application to be bullet-proof against external libraries that can (and often do) raise Exception(u'nonascii'), I cannot use python's logger.exception() directly, as it will end up with UnicodeDecodeError. 
The reason is hidden in Formatter.format() which does:
 s = self._fmt % record.__dict__
One can use his own formatter that can handle UnicodeDecodeError, but many users are quite unaware of such issue and it would be great if Python can handle it by itself.
Here is a simple case.
>>> e = Exception(u'ą')
>>> logging.basicConfig()
>>> logging.getLogger('general').exception(u'ą')
ą
None
>>> logging.getLogger('general').exception(e)
Traceback (most recent call last):
 File "/usr/lib/python2.7/logging/__init__.py", line 842, in emit
 msg = self.format(record)
 File "/usr/lib/python2.7/logging/__init__.py", line 719, in format
 return fmt.format(record)
 File "/usr/lib/python2.7/logging/__init__.py", line 467, in format
 s = self._fmt % record.__dict__
UnicodeEncodeError: 'ascii' codec can't encode character u'\u0105' in position 0: ordinal not in range(128)
Logged from file <stdin>, line 1
>>> unicode(e)
u'\u0105'
>>> str(e)
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode character u'\u0105' in position 0: ordinal not in range(128)
>>>
History
Date User Action Args
2011年06月15日 13:42:01Piotr.Czachursetrecipients: + Piotr.Czachur
2011年06月15日 13:42:01Piotr.Czachursetmessageid: <1308145321.11.0.0545021570949.issue12339@psf.upfronthosting.co.za>
2011年06月15日 13:42:00Piotr.Czachurlinkissue12339 messages
2011年06月15日 13:41:59Piotr.Czachurcreate

AltStyle によって変換されたページ (->オリジナル) /