Skip to content

"not JSON serializable" with byte literals #30

Description

@lazydreamerbliss

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()

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions