diff --git a/stream/ws_client.py b/stream/ws_client.py index a1a96f2d..590bd8d7 100644 --- a/stream/ws_client.py +++ b/stream/ws_client.py @@ -116,7 +116,16 @@ def readline_channel(self, channel, timeout=None): def write_channel(self, channel, data): """Write data to a channel.""" - self.sock.send(chr(channel) + data) + # check if we're writing binary data or not + binary = six.PY3 and type(data) == six.binary_type + opcode = ABNF.OPCODE_BINARY if binary else ABNF.OPCODE_TEXT + + channel_prefix = chr(channel) + if binary: + channel_prefix = six.binary_type(channel_prefix, "ascii") + + payload = channel_prefix + data + self.sock.send(payload, opcode=opcode) def peek_stdout(self, timeout=0): """Same as peek_channel with channel=1."""