- 我正在尝试从一个使用websocket的网站接收数据。它的工作原理如下图所示: websocket握手
以下是获取数据的代码:
async def hello(symb_id: int):
async with websockets.connect("wss://ws.bitpin.ir/", extra_headers = request_header, timeout=15) as websocket:
await websocket.send('{"method":"sub_to_price_info"}')
recv_msg = await websocket.recv()
if recv_msg == '{"message": "sub to price info"}':
await websocket.send(json.dumps({"method":"sub_to_market","id":symb_id}))
recv_msg = await websocket.recv()
counter = 1
while(1):
msg = await websocket.recv()
print(counter, msg[:100], end='\n\n')
counter+=1
asyncio.run(hello(1))
收到约100条消息后,我遇到了这个错误:
websockets.exceptions.ConnectionClosedOK: code = 1000 (OK), no reason
- 我尝试设置
超时时间
和请求头
,但这些都没有帮助。
PING
ж¶ҲжҒҜжҳҜеҗҰжҳҜз”ұwebsockets
жЁЎеқ—иҮӘеҠЁеҸ‘йҖҒзҡ„пјҹ - Mostafa Najmi