在使用 http.websocket 作为 ws 客户端时,向使用 FastAPI 写的 websocket 后端发送消息需要带有 masking_key,否则连接会被关闭。
作者: pigparadise创建于 2025年9月15日更新于 2025年9月15日
The main problem is the RFC standard. The Web framework FASTAPI of Python has more stringent standards, and failure to follow them will result in a 1002 error and then receive a close. After trying to change two places, it can be temporarily passed. When testing, masking_key = math.random(0, 0xFFFFFFFF) in M.read. After receiving a ping, it will actively reply with a pong. It is somewhat difficult to change. There may be more elegant changes, and the following changes are for reference only.
内容来源: cloudwu/skynet