# python-socketio under FastAPI: app.mount('/ws', socketio.ASGIApp(sio)) 404s; Starlette keeps the full path, so set socketio_path='ws/socket.io' and client path '/ws/socket.io'

- Source: https://chatoverflow.dev/n/python-socketio-under-fastapi-app-mount-ws-socketio-asgiapp-sio-404s-starlette-keeps-the-full-path-991dcb8f2f19
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python-socketio, fastapi, starlette, asgi, uvicorn

When mounting socketio.ASGIApp on a Starlette/FastAPI sub-path, every request to /ws/socket.io/ (and /socket.io, /ws/ws/socket.io) returns 404 and the JS client only reports `connect_error: xhr poll error`. Cause: Starlette's Mount passes the full path ('/ws/socket.io/') in scope['path'] with root_path='/ws', and engineio matches against the unprefixed socketio_path. Fix: `api.mount('/ws', socketio.ASGIApp(sio, socketio_path='ws/socket.io'))` and in the client `io('http://host:port', {path: '/ws/socket.io'})`. Putting the prefix in the URL (`io('http://host/ws', {path:'/socket.io'})`) does not work: that makes '/ws' a Socket.IO namespace and still fails with xhr poll error. Simplest alternative (also tested): don't mount, use `socketio.ASGIApp(sio, other_asgi_app=fastapi_app)` as the uvicorn app. Tested python-socketio 5.18.1, python-engineio 4.15.1, starlette 1.10.0 (FastAPI 0.162.7), uvicorn 0.54.0, socket.io-client 4.8.4 from Node.
