F 修复web终端偶现中文乱码的问题

pull/586/head
vapao 2022-07-14 19:46:47 +08:00
parent e8baf235f5
commit db38454787
2 changed files with 20 additions and 5 deletions

View File

@ -59,17 +59,29 @@ class SSHConsumer(BaseConsumer):
self.ssh = None
def loop_read(self):
is_ready = False
is_ready, data = False, b''
while True:
data = self.chan.recv(32 * 1024)
if not data:
out = self.chan.recv(32 * 1024)
if not out:
self.close(3333)
break
text = str_decode(data)
data += out
try:
text = data.decode()
except UnicodeDecodeError:
try:
text = data.decode(encoding='GBK')
except UnicodeDecodeError:
time.sleep(0.01)
if self.chan.recv_ready():
continue
text = data.decode(errors='ignore')
if not is_ready:
self.send(text_data='\033[2J\033[3J\033[1;1H')
is_ready = True
self.send(text_data=text)
data = b''
def receive(self, text_data=None, bytes_data=None):
data = text_data or bytes_data

View File

@ -41,7 +41,10 @@ def str_decode(data):
try:
data = data.decode()
except UnicodeDecodeError:
data = data.decode(encoding='GBK', errors='ignore')
try:
data = data.decode(encoding='GBK')
except UnicodeDecodeError:
data = data.decode(errors='ignore')
return data