Bugfix: win cmd stdout encoding bug - [thanks to @sharpdeep]
This commit is contained in:
@@ -554,6 +554,22 @@ class WebWeixin(object):
|
||||
if pm: return pm.group(1)
|
||||
return '未知'
|
||||
|
||||
class UnicodeStreamFilter:
|
||||
def __init__(self, target):
|
||||
self.target = target
|
||||
self.encoding = 'utf-8'
|
||||
self.errors = 'replace'
|
||||
self.encode_to = self.target.encoding
|
||||
|
||||
def write(self, s):
|
||||
if type(s) == str:
|
||||
s = s.decode('utf-8')
|
||||
s = s.encode(self.encode_to, self.errors).decode(self.encode_to)
|
||||
self.target.write(s)
|
||||
|
||||
if __name__ == '__main__':
|
||||
if sys.stdout.encoding == 'cp936':
|
||||
sys.stdout = UnicodeStreamFilter(sys.stdout)
|
||||
|
||||
webwx = WebWeixin()
|
||||
webwx.start()
|
||||
|
||||
Reference in New Issue
Block a user