If we are running in an environment that doesn't have en_US.UTF-8, and is configured for C.UTF-8, we need to delete the "c.utf8" alias from the locale module before we check our locale with getlocale(). Otherwise, Python will report the wrong locale, as demonstrated below:
[root@53bd20de2fd8 /]# python3
Python 3.7.4rc1 (default, Jun 26 2019, 10:45:53)
[GCC 9.1.1 20190605 (Red Hat 9.1.1-2)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> import dnf
Failed to set locale, defaulting to C.UTF-8
>>> locale.getlocale(locale.LC_TIME)
('en_US', 'UTF-8')
>>> del(locale.locale_alias['c.utf8'])
>>> locale.getlocale(locale.LC_TIME)
('C', 'UTF-8')
Another option for locale handling:
If we are running in an environment that doesn't have en_US.UTF-8, and is configured for C.UTF-8, we need to delete the "c.utf8" alias from the locale module before we check our locale with getlocale(). Otherwise, Python will report the wrong locale, as demonstrated below: