[Python] Cannot access path in websockets.serve handler

Discussão em 'Python' iniciado por Stack, Novembro 28, 2024.

  1. Stack

    Stack Membro Participativo

    I cannot find a way to access the path of a websocket connection, docs say Receiving the request path in the second parameter of connection handlers is deprecated.

    python version: 3.12.6 websockets version: 14.1

    async def handler(websocket: ServerConnection):
    print(websocket.path) ## AttributeError: 'ServerConnection' object has no attribute 'path'

    async def main():
    server = await websockets.serve(
    handler,
    "0.0.0.0",
    9000,
    )

    print("Server started on 0.0.0.0:9000")

    await server.wait_closed()

    if __name__ == "__main__":
    asyncio.run(main())

    Continue reading...

Compartilhe esta Página