You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WebSocket接收数据解码求助:Ruby与Python解压仍有残留

解码WebSocket接收数据遇到的问题

接收的原始数据

使用Ruby(依赖faye/websocket和eventmachine)接收的原始数据为:

[31, 139, 8, 0, 0, 0, 0, 0, 0, 3, 53, 206, 177, 13, 194, 48, 20, 69, 209, 251, 252, 191, 109, 8, 16, 69, 8, 9, 165, 97, 2, 87, 41, 89, 33, 18, 29, 19, 192, 18, 76, 192, 60, 217, 34, 179, 144, 150, 1, 136, 11, 244, 138, 219, 156, 226, 189, 64, 111, 196, 131, 120, 110, 245, 85, 40, 178, 34, 159, 137, 79, 210, 64, 46, 218, 12, 108, 47, 52, 39, 118, 13, 123, 56, 64, 11, 38, 28, 8, 53, 89, 159, 117, 161, 247, 222, 173, 163, 195, 39, 155, 44, 94, 185, 121, 130, 163, 103, 184, 187, 248, 179, 69, 139, 172, 90, 175, 54, 86, 155, 180, 30, 200, 163, 143, 254, 3, 73, 113, 41, 98, 142, 0, 0, 0]  

使用Python(依赖asyncio和websockets)接收的原始数据为:

b'\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x035\xce\xb1\r\xc20\x14E\xd1\xfb\xfc\xbfm\x08\x10E\x08\t\xa5a\x02W)Y!\x12\x1d\x13\xc0\x12L\xc0<\xd9"\xb3\x90\x96\x01\x88\x0b\xf4\x8a\xdb\x9c\xe2\xbd@o\xc4\x83xn\xf5U(\xb2"\x9f\x89O\xd2@.\xda\x0cl/4\'v\r{8@\x0b&\x1c\x085Y\x9fu\xa1\xf7\xde\xad\xa3\xc3\'\x9b,^\xb9y\x82\xa3g\xb8\xbb\xf8\xb3E\x8b\xacZ\xaf6V\x9b\xb4\x1e\xc8\xa3\x8f\xfe\x03Iq)b\x8e\x00\x00\x00'

我的尝试

Ruby实现

使用pack('c*')处理数据后,通过Zlib::GzipReader解压,得到的结果仍有乱码,但可识别部分链接:

0k��0l��0���0���0���0���0���0���0���0���0���0���0���0���0���0���0���0���0���0���0��0�0�0���0���0���0���0Bhttps://player.twitch.tv/?channel=esbbasketball1&parent=winline.rue��Bhttps://player.twitch.tv/?channel=esbbasketball3&parent=winline.run��3https://bigsports.servicecdn.ru/streams/9952_499736���2154391���
38272563���Ahttps://player.twitch.tv/?channel=gt_sports_tv2&parent=winline.ru���Ahttps://player.twitch.tv/?channel=gt_sports_tv1&parent=winline.ru���0

Python实现

使用gzip.decompress()解压后仍有压缩残留,尝试struct.unpack_from('hhl', ...)也未得到有效结果,解压前后的unpack结果分别为(-29921, 8, 3513385716622361344)和(121, 256, 140738648382701667)。

期望结果

最终解码后的目标数据应为类似如下的JSON格式:

42["sb_odds_change","{\"id\":35285604,\"type\":\"match\",\"provider\":2,\"status\":1,\"timestamp\":1672170170534,\"markets\":[{\"id\":60,\"specifiers\":\"\",\"status\":0,\"provider\":2,\"meta\":{\"dataVersion\":46,\"lA\":0,\"lH\":0},\"timestamp\":1672170170534,\"outcomes\":[{\"id\":1,\"type\":\"predefined\",\"odds\":14,\"active\":false,\"state\":1},{\"id\":3,\"type\":\"predefined\",\"odds\":1.23,\"active\":false,\"state\":1},{\"id\":2,\"type\":\"predefined\",\"odds\":4.3,\"active\":false,\"state\":1}],\"state\":1,\"weight\":2},{\"id\":63,\"specifiers\":\"\",\"status\":0,\"provider\":2,\"meta\":{\"dataVersion\":46,\"lA\":0,\"lH\":0},\"timestamp\":1672170170534,\"outcomes\":[{\"id\":9,\"type\":\"predefined\",\"odds\":3.75,\"active\":false,\"state\":1}"]

仅出于学习目的尝试,无商业用途,目前陷入困境,恳请提供解决方案或指导方向。


内容的提问来源于stack exchange,提问作者SonyMag

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 17:55:20