[New-bugs-announce] [issue5562] Locale-based date formatting crashes on non-ASCII data

Antoine Pitrou report at bugs.python.org
Wed Mar 25 20:46:18 CET 2009

New submission from Antoine Pitrou <pitrou at free.fr>:

Locale-based date formatting in py3k (using strftime) crashes when asked
to format a month name (or day, I assume) containing non-ASCII characters:

>>> import time
>>> import locale
>>> time.strftime("%B", (2009,2,1,0,0,0,0,0,0))
>>> locale.setlocale(locale.LC_TIME, "fr_FR")
>>> time.strftime("%B", (2009,2,1,0,0,0,0,0,0))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'utf8' codec can't decode bytes in position 1-3:
invalid data

It works if I specify the encoding explicitly in the locale name so as
to coincide with the encoding specified in the error message above (but
that's assuming the given encoding-specific locale *is* installed):

>>> locale.setlocale(locale.LC_TIME, "fr_FR.UTF-8")
>>> time.strftime("%B", (2009,2,1,0,0,0,0,0,0))

components: Library (Lib)
messages: 84163
nosy: pitrou
priority: high
severity: normal
status: open
title: Locale-based date formatting crashes on non-ASCII data
type: behavior
versions: Python 3.0, Python 3.1

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list