[issue43115] locale.getlocale fails if locale is set

Marc-Andre Lemburg report at bugs.python.org
Wed Feb 17 05:19:37 EST 2021


Marc-Andre Lemburg <mal at egenix.com> added the comment:

On 17.02.2021 10:55, Anders Munch wrote:
>>>> import locale
>>>> locale.setlocale(locale.LC_ALL, 'en_DE')
> 'en_DE'
>>>> locale.getlocale()
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "C:\flonidan\env\Python38-64\lib\locale.py", line 591, in getlocale
>     return _parse_localename(localename)
>   File "C:\flonidan\env\Python38-64\lib\locale.py", line 499, in _parse_localename
>     raise ValueError('unknown locale: %s' % localename)
> ValueError: unknown locale: en_DE

The locale module does not know this encoding, so cannot
guess the encoding. Since getlocale() returns the language
code and encoding, this fails.

If you add the encoding, you should be fine:

>>> locale.setlocale(locale.LC_ALL, 'en_DE.UTF-8')
'en_DE.UTF-8'
>>> locale.getlocale()
('en_DE', 'UTF-8')

----------
nosy: +lemburg

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43115>
_______________________________________


More information about the Python-bugs-list mailing list