diff --git a/stream/ws_client.py b/stream/ws_client.py index cf8a3fe9..7705627a 100644 --- a/stream/ws_client.py +++ b/stream/ws_client.py @@ -24,6 +24,7 @@ import six import ssl from six.moves.urllib.parse import urlencode, quote_plus, urlparse, urlunparse +import chardet STDIN_CHANNEL = 0 STDOUT_CHANNEL = 1 @@ -181,7 +182,8 @@ def update(self, timeout=0): elif op_code == ABNF.OPCODE_BINARY or op_code == ABNF.OPCODE_TEXT: data = frame.data if six.PY3: - data = data.decode("utf-8") + encode = chardet.detect(data).get('encoding') + data = data.decode(encode or "utf-8") if len(data) > 1: channel = ord(data[0]) data = data[1:]