I have carefully read answers from Setting the correct encoding when piping stdout in Python but:
the solution
export PYTHONIOENCODING=utf8
does not work if you're not calling the process yourself. Example: here the process is called from Apache + mod_cgi, and runningexport PYTHONIOENCODING=utf8
in Bash does not change anything; I still haveimport sys; print(str(sys.stdout.encoding))
givingANSI_X3.4-1968
.the solution
import sys, codecs sys.stdout = codecs.getwriter('utf8')(sys.stdout)
probably worked on Python 2.7 but not really for Python 3, because then,
print(s)
expectss
being bytes, which is not very handy
Should we use a way to permanently export PYTHONIOENCODING=utf8
for all processes of the system (that is persistent, even after a reboot), if so how?