Describe the bug
Websocket routes appear to only work on the main FastAPI object, not on APIRouter objects. When the same function is copied from a FastAPI object to an APIRouter object instead of working properly it just throws a 403.
To Reproduce
Steps to reproduce the behavior:
from fastapi import FastAPI
app = FastAPI()
@app.websocket_route("/hello")
async def hello(websocket):
await websocket.accept()
await websocket.send_text("Hello!")
response = await websocket.receive_text()
print(response)
await websocket.close()
print("Closed")
hello
to an APIRouter fails:# main.py
from fastapi import FastAPI
import other
app = FastAPI()
app.include_router(other.router)
# other.py
from fastapi import APIRouter
router = APIRouter()
@router.websocket_route("/routerhello")
async def hello(websocket):
await websocket.accept()
await websocket.send_text("Router Hello!")
response = await websocket.receive_text()
print(response)
await websocket.close()
print("Router Closed")
Expected behavior
I expect a websocket route to work on both a FastAPI and APIRouter object.
Screenshots
Not applicable.
Environment:
Additional context
Testing websocket client side with websocat
.
Thanks for the report!
It was fixed by @euri10 in PR https://github.com/tiangolo/fastapi/pull/100.
It is available in FastAPI verson 0.10.0
. :tada: :rocket:
Just tested it out! I'm impressed at how quickly that was fixed, thanks!
Awesome! Kudos to @euri10 for his work 馃榾馃嵃馃尞
Thanks @iwoloschin for reporting back and closing the issue.
Most helpful comment
Thanks for the report!
It was fixed by @euri10 in PR https://github.com/tiangolo/fastapi/pull/100.
It is available in FastAPI verson
0.10.0
. :tada: :rocket: