Answer the question
In order to leave comments, you need to log in
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())
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question