What type of encoding/compression is this?
Question:
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'x1fx8bx08x00x00x00x00x00x00x035xcexb1rxc20x14Exd1xfbxfcxbfmx08x10Ex08txa5ax02W)Y!x12x1dx13xc0x12Lxc0<xd9"xb3x90x96x01x88x0bxf4x8axdbx9cxe2xbd@oxc4x83xnxf5U(xb2"[email protected]/4'vr{8@x0b&x1cx085Yx9fuxa1xf7xdexadxa3xc3'x9b,^xb9yx82xa3gxb8xbbxf8xb3Ex8bxacZxaf6Vx9bxb4x1exc8xa3x8fxfex03Iq)bx8ex00x00x00'
If i will use gzip.decompress(message)
it will looks:
b'x1fx8bx08x00x00x00x00x00x00x00xd3axc8a``xe0axb04xd536xd4325x01bx00x99xe6x82x81x14x00x00x00'
,l
95.31.254.25
b'x1fx8bx08x00x00x00x00x00x00x00x0bcx00x00-xe88xadx02x00x00x00'
V
Thanks in advance guys!
Answers:
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'yx00x00x01x87x00x01x00cx00x05x17x0ex01xf4x01x02,x01x03,x01x04xc8x00x05dx00x062x00x07,x01x082x00tx1ex00nx14x00x0bnx00x0cx00x00rx00x00x0ex00x00x03x01x00x04x00x00x00x02x01x00x04x00x07x01xeax01xeax01x02x19x04x19x04x03x10x00x10x00x04xb1x03xb1x03x05:x00Nx04x06x00x00x12x04x07x00x00Ux04x01x00x00x07x01xeax01xeax01x02xebx01xebx01x03x19x04x19x04x04x10x00x10x00x05xb1x03xb1x03x06x01x00x01x00x07Kx04Kx04'
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'x1fx8bx08x00x00x00x00x00x00x035xcexb1rxc20x14Exd1xfbxfcxbfmx08x10Ex08txa5ax02W)Y!x12x1dx13xc0x12Lxc0<xd9"xb3x90x96x01x88x0bxf4x8axdbx9cxe2xbd@oxc4x83xnxf5U(xb2"[email protected]/4'vr{8@x0b&x1cx085Yx9fuxa1xf7xdexadxa3xc3'x9b,^xb9yx82xa3gxb8xbbxf8xb3Ex8bxacZxaf6Vx9bxb4x1exc8xa3x8fxfex03Iq)bx8ex00x00x00'
If i will use gzip.decompress(message)
it will looks:
b'x1fx8bx08x00x00x00x00x00x00x00xd3axc8a``xe0axb04xd536xd4325x01bx00x99xe6x82x81x14x00x00x00'
,l
95.31.254.25
b'x1fx8bx08x00x00x00x00x00x00x00x0bcx00x00-xe88xadx02x00x00x00'
V
Thanks in advance guys!
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'yx00x00x01x87x00x01x00cx00x05x17x0ex01xf4x01x02,x01x03,x01x04xc8x00x05dx00x062x00x07,x01x082x00tx1ex00nx14x00x0bnx00x0cx00x00rx00x00x0ex00x00x03x01x00x04x00x00x00x02x01x00x04x00x07x01xeax01xeax01x02x19x04x19x04x03x10x00x10x00x04xb1x03xb1x03x05:x00Nx04x06x00x00x12x04x07x00x00Ux04x01x00x00x07x01xeax01xeax01x02xebx01xebx01x03x19x04x19x04x04x10x00x10x00x05xb1x03xb1x03x06x01x00x01x00x07Kx04Kx04'