locale.Error: unsupported locale setting

Bug #2020064 reported by Mateusz Pawlowski
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Landscape Client
Confirmed
Undecided
Unassigned

Bug Description

OS: Ubuntu 20.04.6 LTS
Landscape client: 23.02-0ubuntu1

Due to missing locale, the landscape client couldn't report the list of installed packages to the landscape server (SAAS).

2023-05-10 17:23:10,675 WARNING [MainThread] Package reporter output:
b'Traceback (most recent call last):
  File "/usr/bin/landscape-package-reporter", line 10, in <module>
    main(sys.argv[1:])
  File "/usr/lib/python3/dist-packages/landscape/client/package/reporter.py", line 872, in main
    locale.setlocale(locale.LC_CTYPE, ("C", "UTF-8"))
  File "/usr/lib/python3.8/locale.py", line 608, in setlocale
    return _setlocale(category, locale)
locale.Error: unsupported locale setting
'

As a result, the server kept reporting available updates for the machine and when the update was triggered it failed with the following error reported in the task activity.

"Package data has changed. Please retry the operation."

For example on the affected client machine the "apt list --installed | grep dnsmasq-base" gives the output
"dnsmasq-base/focal-updates,focal-security,now 2.80-1.1ubuntu1.7 amd64

However, landscape server keeps reporting that update (2.80-1.1ubuntu1.7) is available.

Tags: sts
Revision history for this message
Juanmi Taboada (juanmitaboada) wrote :

I think the client machine should address this bug. A hint to resolve it could be:
sudo locale-gen en_US.UTF-8
sudo update-locale LANG=C.UTF-8

Landscape Client could also try to prevent future failures when detected by applying the solution proposed above:

@@ -3,6 +3,7 @@
 except ImportError:
     import urllib.parse as urlparse

+import subprocess
 import locale
 import logging
 import time
@@ -943,7 +944,12 @@
 def main(args):
     # Force UTF-8 encoding only for the reporter, thus allowing libapt-pkg to
     # return unmangled descriptions.
- locale.setlocale(locale.LC_CTYPE, ("C", "UTF-8"))
+ try:
+ locale.setlocale(locale.LC_CTYPE, ("C", "UTF-8"))
+ except locale.Error:
+ subprocess.run(["sudo", "locale-gen", "en_US.UTF-8"], check=True)
+ subprocess.run(["sudo", "update-locale", "LANG=C.UTF-8"], check=True)
+ raise

     if "FAKE_GLOBAL_PACKAGE_STORE" in os.environ:
         return run_task_handler(FakeGlobalReporter, args)

There is a PR with this proposed solution at:
https://github.com/CanonicalLtd/landscape-client/pull/161

Changed in landscape-client:
status: New → Confirmed
Revision history for this message
Juanmi Taboada (juanmitaboada) wrote :

I will go with Mitch's suggestion to address this issue through the postinst script during package installation.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.