Closed cuipy closed 3 years ago
websocket-server不支持中文,解决方法有两个:
decoded = bytearray() for char in self.read_bytes(payload_length): char ^= masks[len(decoded) % 4] decoded.append(char) decoded = str(decoded, encoding="utf-8")
bytestream = bytearray() for ch in message: bytestream.append(ord(ch)) message = str(bytestream, encoding="utf-8")
主要因为库中解码过程中使用chr()对每个接收的字节处理,从而破坏了GBK编码的汉字,或者其他编码的多字节字符。使用str()则不会破坏。可以尝试下,我这边解决了
Feel free to make a PR if there is a known solution :+1:
Closing since I can't understand any of this. Feel free to post a solution in English and I can add it.
if client send any words with gbk charset,i receive is error words . you can test with this website: http://www.blue-zero.com/WebSocket/ it is pain of chinese user