M
M
Master Ruby2021-07-02 19:41:40
Python
Master Ruby, 2021-07-02 19:41:40

How to decode response from web socket?

import asyncio
import logging
import json
import websockets
import gzip

logging.basicConfig(level=logging.INFO)

data = {
    "GET": "wss://wss.winline.ru/data_ng?client=site HTTP/1.1",
    "Host": "wss.winline.ru",
    "Connection": "Upgrade",
    "Cache-Control": "no-cache",
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36",
    "Upgrade": "websocket",
    "Origin": "https://winline.ru",
    "Sec-WebSocket-Version": "13",
    "Accept-Language": "ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7",
    "Sec-WebSocket-Key": "6LVMkrtXQjpfqgFzs8NW4A==",
    "Sec-WebSocket-Extensions": "permessage-deflate; client_max_window_bits",
}

request = json.dumps(data)


async def echo():
    """Connect to socket, send message&get response"""
    uri = "wss://wss.winline.ru/data_ng?client=site"
    async with websockets.connect(uri) as websocket:
        await websocket.send(request)
        response = await websocket.recv()
        print(dir(response))
        content = gzip.decompress(response)
        # log_message(response) - if u a need logs and comment out the next line
        logging.info(content)


def log_message():
    """Login message from server"""
    logger = logging.getLogger()
    logger.setLevel(logging.DEBUG)


if __name__ == '__main__':
    while True:
        asyncio.get_event_loop().run_until_complete(echo())

I get b'\x8a\x04\x01\x03\r\x1a\x00\x00\x00\x01\x1a\x00\x00\x00\x1f\x05{\x00P!\xe2`\x18\x00\ .. I don't know how to decode, I tried both decode and gzip.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question