【websockets】python使用websockets库调用websocket接口
class WsClient(object): def __init__(self, url): self.url = url async def test(self): async with websockets.connect(self.url + '/test') as websocket: await websocket.send('{"chan": "test"}') while True: recv_text = await websocket.recv() debug_logger.info(recv_text) def run_test(self): asyncio.get_event_loop().run_until_complete(self.test())