Home > OS >  What type of encoding/compression is this?
What type of encoding/compression is this?

Time:12-28

So, I am trying to decode/decompress web socket receive, but I don`t know what should I use, gzip, lib and etc.

def on_message(ws, message):
    print(message)


def on_error(ws, error):
    print(error)


def on_close(ws, close_status_code, close_msg):
    print("### closed ###")


def on_open(ws):
    print("[*] Opened connection.")  
    msg = ["lang", "AA==", "data", "WINLINE", "getdate"]
    [ws.send(m) for m in msg]

if __name__ == "__main__":
    ws = websocket.WebSocketApp(
        url="wss://wss.winline.ru/data_ng?",
        on_open=on_open,
        on_message=on_message,
        # header=headers
    )

    ws.run_forever(dispatcher=rel)  # Set dispatcher to automatic reconnection
    rel.signal(2, rel.abort)  # Keyboard Interrupt
    rel.dispatch()
    websocket.enableTrace(True)

This is websocket receive:

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'

If i will use gzip.decompress(message) it will looks:

b'\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x00\xd3a\xc8a``\xe0a\xb04\xd536\xd4325\x01b\x00\x99\xe6\x82\x81\x14\x00\x00\x00'
,l
  95.31.254.25
b'\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x00\x0bc\x00\x00-\xe88\xad\x02\x00\x00\x00'
V

Thanks in advance guys!

CodePudding user response:

Your "This is websocket receive:" is a perfectly valid gzip stream. When I use Python's gzip.decompress() on it, it decompresses correctly to:

b'y\x00\x00\x01\x87\x00\x01\x00c\x00\x05\x17\x0e\x01\xf4\x01\x02,\x01\x03,\x01\x04\xc8\x00\x05d\x00\x062\x00\x07,\x01\x082\x00\t\x1e\x00\n\x14\x00\x0b\n\x00\x0c\x00\x00\r\x00\x00\x0e\x00\x00\x03\x01\x00\x04\x00\x00\x00\x02\x01\x00\x04\x00\x07\x01\xea\x01\xea\x01\x02\x19\x04\x19\x04\x03\x10\x00\x10\x00\x04\xb1\x03\xb1\x03\x05:\x00N\x04\x06\x00\x00\x12\x04\x07\x00\x00U\x04\x01\x00\x00\x07\x01\xea\x01\xea\x01\x02\xeb\x01\xeb\x01\x03\x19\x04\x19\x04\x04\x10\x00\x10\x00\x05\xb1\x03\xb1\x03\x06\x01\x00\x01\x00\x07K\x04K\x04'
  • Related