-
Notifications
You must be signed in to change notification settings - Fork 40
Closed
Description
When using jsonrpcserver over WebSocket with Python 3.10, there is no problem, but with Python 3.12, an error occurs:
...\Lib\site-packages\websockets\asyncio\server.py", line 373, in conn_handler
await self.handler(connection)
^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: main() missing 1 required positional argument: 'path'
Below is my test codes:
server.py
import asyncio
from jsonrpcserver import method, Success, Result, async_dispatch, serve
import websockets
@method
async def ping() -> Result:
return Success("pong")
async def main(websocket, path):
if response := await async_dispatch(await websocket.recv()):
await websocket.send(response)
async def start_server():
server = await websockets.serve(main, "localhost", 8765)
await server.wait_closed()
if __name__ == "__main__":
asyncio.run(start_server())
client.py
import asyncio
import websockets
async def send_ping():
uri = "ws://localhost:8765"
async with websockets.connect(uri) as websocket:
request = '{"jsonrpc": "2.0", "method": "ping", "id": 1}'
await websocket.send(request)
response = await websocket.recv()
print(f"Received: {response}")
if __name__ == "__main__":
asyncio.run(send_ping())
Metadata
Metadata
Assignees
Labels
No labels