Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

emmmmm...Why? #2983

Closed
Hamisan opened this issue Mar 23, 2021 · 7 comments
Closed

emmmmm...Why? #2983

Hamisan opened this issue Mar 23, 2021 · 7 comments

Comments

@Hamisan
Copy link

Hamisan commented Mar 23, 2021

main.py

from fastapi import FastAPI
from child import child_router


app = FastAPI()

# want: /child/info -> √ /child/ws -> √
# got: /child/info -> √ /child/ws -> ×  /ws -> √
# app.include_router(child_router)

# want: /child/info -> ×, /child/ws -> ×, /child/child/info -> √  /child/child/ws √
# got: /child/info -> ×, /child/ws -> √, /child/child/info -> √ /child/child/ws ×
app.include_router(child_router, prefix=child_router.prefix)

child.py

from fastapi import APIRouter, WebSocket


child_router = APIRouter(
    prefix="/child"
)


@child_router.websocket("/ws")
async def child_websocket(websocket: WebSocket):
    await websocket.accept()
    while True:
        try:
            await websocket.receive()
        except:
            pass

@child_router.get("/info")
async def get_child_info():
    return "child information"
@Hamisan Hamisan added the question Question or problem label Mar 23, 2021
@Kludex
Copy link
Sponsor Collaborator

Kludex commented Mar 23, 2021

I understand your issue, but do you really think this is a way to express yourself?

Anyway, it's a bug. You should not add the prefix on the APIRouter if using websockets (until it's solved).

There's a PR to solve that: #2640

This is a duplicated issue btw, do you mind closing it? Check the related issues inside the PR above /\

@Hamisan
Copy link
Author

Hamisan commented Mar 24, 2021

我了解您的问题,但是您真的认为这是表达自己的方式吗?

无论如何,这是一个错误。APIRouter如果使用websockets ,则不应在前缀上添加前缀(直到解决)。

已解决的PR已创建,正在等待审查:#2640

orz, sorry, my poor English. It's a good way for me to express myself

@Kludex
Copy link
Sponsor Collaborator

Kludex commented Mar 24, 2021

没关系。不用担心

如果您需要任何帮助,请告诉我

:)

@waynerv
Copy link
Contributor

waynerv commented Mar 24, 2021

At the very least you should provide a readable issue title.

@Hamisan
Copy link
Author

Hamisan commented Mar 24, 2021

At the very least you should provide a readable issue title.

受教了. > - < . -- 菜鸟敬上

@tiangolo
Copy link
Owner

tiangolo commented Nov 27, 2022

Thanks for the help here everyone! 👏 🙇

If that solves the original problem, then you can close this issue @Hamisan ✔️

Sorry for the long delay! 🙈 I wanted to personally address each issue/PR and they piled up through time, but now I'm checking each one in order.

@github-actions
Copy link
Contributor

Assuming the original need was handled, this will be automatically closed now. But feel free to add more comments or create new issues or PRs.

@tiangolo tiangolo reopened this Feb 27, 2023
Repository owner locked and limited conversation to collaborators Feb 27, 2023
@tiangolo tiangolo converted this issue into discussion #6740 Feb 27, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Projects
None yet
Development

No branches or pull requests

4 participants