Skip to content

An error occurs when using Jsonrpcserver over WebSocket with Python3.12 #286

@8188

Description

@8188

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions