Comment 1 for bug 1902546

Revision history for this message
Tom Haddon (mthaddon) wrote :

Ok, so I've finally figured out what's going on here.

We don't pass through any environment variables to Mojo when executing this, and when using universal_newlines=True text is streamed using the encoding returned by locale.getpreferredencoding(False). Because we've not passed through (for example LANG) we end up with a preferred encoding of ANSI_X3.4-1968, which then fails on any unicode characters.

I was able to confirm the following fixes things (will discuss with a few folks whether this is the right approach and propose an MP):

=== modified file 'mojo/juju/status.py'
--- old/mojo/juju/status.py 2021-02-05 12:12:08 +0000
+++ new/mojo/juju/status.py 2021-04-15 09:47:31 +0000
@@ -1,5 +1,6 @@
 from __future__ import division, print_function
 import datetime
+import locale
 import logging
 import os
 import subprocess
@@ -41,6 +42,7 @@

     cmd.extend(command)
     try:
+ locale.setlocale(locale.LC_ALL, os.environ.get('LANG', 'en_US.UTF-8'))
         return subprocess.check_output(cmd, universal_newlines=True)
     except subprocess.CalledProcessError as cpe:
         if command_timeout is not None: