I am exploring websocket which is sending data encoded in zlib
the parameter of endocing is zlib-stream
. I wanted to use zlib
library but it seems not to work.
import zlib
print(zlib.decompress(text.encode()))
It throws me an error zlib.error: Error -3 while decompressing data: incorrect header check
. It is a discord url wss://gateway.discord.gg/?encoding=json&v=8&compress=zlib-stream
This is an example,,binary message'' wp0KLShOhRZ6FibUSIWgpRPGpuCZaCNqpULQIgFLYNIGlt2UFEcGwyQVAgAAAP//
You need to create decompression object and decompress every message from the start. You can't just decompress an arbitrary message.
decompress_obj = zlib.decompressobj()
for compressed_message in messages:
message = decompress_obj.decompress(compressed_message)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.