I've tried many things, but this method is the best. Characters are not garbled when started as a web server or locally.
import io
import os
import sys
html_body = 'HTML format'
if type(sys.stdout) == io.TextIOWrapper:
sys.stdout = io.TextIOWrapper(
sys.stdout.buffer,
encoding='utf-8'
print ('Content-type: text/html; charset=UTF-8\r\n')
print (html_body)
Recommended Posts