For a few days I am trying to solve my following problem but with no success.
So I have a bash script which successfully executes by calling command through a subprocess.getstatusoutput method. The bash script itself returns some results by logging out the string on stdout. I do indeed get the output of executed bash script from the subprocess.getstatusoutput but the output does not include intended Slovenian special language characters, but instead replaces them with the ‘?’.
By executing the bash script from the terminal, there is no problem with special language characters, only when I run it from the .py script by calling getstatusoutput method.
Due to described problem, here is an example:
država -> dr?ava
I have a Ubuntu 18.04 server with installed python version 3.8.9.
2
Answers
Thanks for your answer. I have executed this code locally, and the result that gets logged out on stdout is the same. Meanwhile, I've tried to run the exact same code that you provided in my production environment, on the server and following error is thrown:
There is something wrong going on while executing
subprocess.run
method because if I do comment this line, there is no error thrown.Server is using default terminal and the result of
grep -i "fontface" /etc/default/console-setup
returnsFONTFACE="fixed"
.We do use Apache Server with mod_wsgi: apache
Locale details are following: locale
The easy way to avoid this problem is to switch from
getstatusoutput
torun
(withouttext=True
), and to handle the returned stdout in a way that avoids trying to convert it from a bytestring to Unicode text.For example:
See this working at https://replit.com/@CharlesDuffy2/ActiveEffectiveLocations#main.py