import asyncio
import uvloop
import websockets
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
HEART_BEAT_INTERVAL = 10 # Replace with your desired heartbeat interval
async def connect():
async for websocket in websockets.connect(
uri="wss://...",
max_queue=None,
ping_interval=60,
ping_timeout=60
):
try:
while True:
try:
message = await asyncio.wait_for(websocket.recv(), timeout=HEART_BEAT_INTERVAL)
print(message)
except asyncio.TimeoutError:
print("Timeout, no message received")
continue
except websockets.ConnectionClosed:
continue
except asyncio.CancelledError:
break
if __name__ == '__main__':
asyncio.run(connect())
File "uvloop/loop.pyx", line 1517, in uvloop.loop.Loop.run_until_complete
File "/home/albert/git/crypto_loops/CryptoLoops/debug/uvloop_error.py", line 12, in connect
async for websocket in websockets.connect(
File "/home/albert/miniconda3/envs/cyrpto_loops_py/lib/python3.11/site-packages/websockets/asyncio/client.py", line 500, in __aiter__
async with self as protocol:
File "/home/albert/miniconda3/envs/cyrpto_loops_py/lib/python3.11/site-packages/websockets/asyncio/client.py", line 484, in __aenter__
return await self
^^^^^^^^^^
File "/home/albert/miniconda3/envs/cyrpto_loops_py/lib/python3.11/site-packages/websockets/asyncio/client.py", line 441, in __await_impl__
self.connection = await self.create_connection()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/albert/miniconda3/envs/cyrpto_loops_py/lib/python3.11/site-packages/websockets/asyncio/client.py", line 367, in create_connection
_, connection = await loop.create_connection(factory, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "uvloop/loop.pyx", line 2084, in create_connection
File "uvloop/loop.pyx", line 2079, in uvloop.loop.Loop.create_connection
File "uvloop/handles/stream.pyx", line 1007, in uvloop.loop.__uv_stream_buffered_on_read
File "uvloop/loop.pyx", line 109, in uvloop.loop.run_in_context1
File "uvloop/sslproto.pyx", line 379, in uvloop.loop.SSLProtocol.buffer_updated
File "uvloop/sslproto.pyx", line 505, in uvloop.loop.SSLProtocol._do_handshake
File "uvloop/sslproto.pyx", line 541, in uvloop.loop.SSLProtocol._on_handshake_complete
File "/home/albert/miniconda3/envs/cyrpto_loops_py/lib/python3.11/site-packages/websockets/asyncio/connection.py", line 961, in connection_made
self.recv_messages = Assembler(
^^^^^^^^^^
TypeError: websockets.asyncio.messages.Assembler() argument after * must be an iterable, not NoneType
After updating to version 14.0 I get this
TypeError: websockets.asyncio.messages.Assembler() argument after * must be an iterable, not NoneType. Did version 14 change the API?Full traceback
This is with
uvloop==0.17.0.