Сообственно код:
import asyncio
from concurrent.futures import TimeoutError as ConnectionTimeoutError
import json
import websockets
async def command(client, data, status=None, timeout=10):
while True:
await client.send(json.dumps(data))
try:
receive = await asyncio.wait_for(client.recv(), timeout)
code = json.loads(receive)["status"][0]
if code == status:
return receive
except (KeyError, ValueError, ConnectionTimeoutError) as err:
print(f"[error from command()] => {err}")
finally:
print(f"[websocket message] =>", receive)
async def main():
async with websockets.connect("ws://example.com") as client:
print(
await command(
client,
{
"auth_token": ""
},
2999,
10,
)
)
if __name__ == "__main__":
asyncio.run(main())
While True поставил, однако он не работает