The problem is that you stdout are not tied to the actual terminal and use ASCII encoding by default. Therefore you need to write sys.stdout.buffer, which is the raw binary output of sys.stdout. This can be done in different ways, the most common seems:
import codecs, sys writer = codecs.getwriter('utf8')(sys.stdout.buffer)
And a writer. In a CGI script, you can replace sys.stdout with a record like this:
sys.stdout = codecs.getwriter('utf8')(sys.stdout.buffer)
Perhaps you are really working to print normally. Try it!
source share