python3通过WebSocket接收到UTF8字符的错误输出?

2024-09-29 03:31:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个javascript发送unicode星字符。在

但python在控制台和日志文件中都将其解释为字母。在

其他unicode字符的格式也不正确。在

    var ws = new WebSocket("ws://127.0.0.1:8888/");

    ws.onopen= function(){
        console.log('\u2605');

        ws.send('\u2605');

        ws.close();
    }

python代码:

^{pr2}$

使用的WebsocketServer库:https://github.com/Pithikos/python-websocket-server

有人知道这里有什么问题吗?在

编辑:

刚在git hub上找到此页面:

https://github.com/Pithikos/python-websocket-server/issues/19

这似乎是lib问题,一些用户发布了解决方案:

bytes([i^masks[idx % 4] for idx, i in enumerate(self.read_bytes(payload_length))]).decode()

但是,我完全不知道该把代码放在哪里。在

非常感谢你的帮助。在


Tags: 文件代码httpsgithubcombyteswsserver
1条回答
网友
1楼 · 发布于 2024-09-29 03:31:52

在WebsocketServer库代码中:

decoded = ""
    for char in self.read_bytes(payload_length):
        char ^= masks[len(decoded) % 4]
        decoded += chr(char)

应替换为:

^{pr2}$

相关问题 更多 >