wssh icon indicating copy to clipboard operation
wssh copied to clipboard

"not JSON serializable" with byte literals

Open lazydreamerbliss opened this issue 7 years ago • 0 comments

Hi,

I was trying to use wssh (thanks to your awesome work) in my project and I found an issue with json.dump (target server is Ubuntu 16.04 LTS):

TypeError: b'Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.10.0-32-generic x86_64)\r\n\r\n * Documentation: https://help.ubuntu.com\r\n * Management: https://landscape.canonical.com\r\n * Support: https://ubuntu.com/advantage\r\n\r\n52 packages can be updated.\r\n2 updates are security updates.\r\n\r\nLast login: Thu Aug 24 14:17:06 2017 from xx.xx.xx.xx\r\r\n' is not JSON serializable Thu Aug 24 14:30:48 2017 <Greenlet at 0x7f75fab22930: <bound method Bridge.forward_outbound of <web_ssh.ssh_bridge.Bridge object at 0x7f76133be048>>(<paramiko.Channel 0 (closed) -> <paramiko.Transpor)> failed with TypeError

That the returned content from remote server is actually byte literals. So I add an if condition to method "forward_outbound()" to detect returned data's type, and everything just works fine after this:

    def forward_outbound(self, channel):
        try:
            while True:
                wait_read(channel.fileno())
                data = channel.recv(1024)
                if not len(data):
                    return
                if isinstance(data, bytes):
                    data = data.decode('utf-8')
                self.websocket.send(json.dumps({'data': data}))
        finally:
            self.close()

lazydreamerbliss avatar Aug 24 '17 05:08 lazydreamerbliss