Skip to content
This repository was archived by the owner on Mar 13, 2022. It is now read-only.

Fix python3 UnicodeDecodeError when use websocket #129

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion stream/ws_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:]
Expand Down