When writing a Python 3.1 CGI script, I run into horrible UnicodeDecodeErrors. However, when running the script on the command line, everything works.
I have encountered the same problem. My environment is Windows10 + Apache 2.4 + Python 3.8.
As I am developing an overlay for Google Earth Pro, which only accept CGI to get dynamic content.
In the best answer, here is the reason but the method does not work.
My solution is:
sys.stdout = codecs.getwriter('utf8')(sys.stdout.buffer)
It works well.