python3 Chinese garbled output problems

You-get recently used this tool to download video, media titles found command-line window display is garbled (but the file manager to display normal). code page of my command line window is 936, sys.stdout.encoding is utf8, sys.getdefaultencoding () is utf8.

Check a lot of information, it will not work. Found on csdn, he is said to add that

sys.stdout = io.TextIOWrapper(sys.stdout.buffer,encoding='utf-8')

To get, but tried it, but tips:

ValueError: I/O operation on closed file

Some people say that can also be used 'Chinese' .encode ( 'utf-8'). Decode (sys.stdout.encoding), too.

And checked a lot of information, but finally found the code to work on Stack Overflow:

sys.stdout.buffer.write(("title: %s" % self.title).encode('gbk'))
sys.stdout.flush()

Guess you like

Origin www.cnblogs.com/badnumber/p/11280286.html