From 5f4978a9949e99a3bb180b4d150ec5e480e988d3 Mon Sep 17 00:00:00 2001 From: Sheng Date: Sun, 22 Mar 2020 14:40:49 +0800 Subject: [PATCH] Set utf-8 as the default encoding if we cannot detect it --- webssh/handler.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/webssh/handler.py b/webssh/handler.py index 87b19c6..0b1f2f7 100644 --- a/webssh/handler.py +++ b/webssh/handler.py @@ -427,12 +427,16 @@ class IndexHandler(MixinHandler, tornado.web.RequestHandler): ] for command in commands: - _, stdout, _ = ssh.exec_command(command, get_pty=True) - data = stdout.read() - logging.debug('{!r} => {!r}'.format(command, data)) - result = self.parse_encoding(data) - if result: - return result + try: + _, stdout, _ = ssh.exec_command(command, get_pty=True) + except paramiko.SSHException as exc: + logging.info(str(exc)) + else: + data = stdout.read() + logging.debug('{!r} => {!r}'.format(command, data)) + result = self.parse_encoding(data) + if result: + return result logging.warn('Could not detect the default ecnoding.') return 'utf-8'