使用FastAPI重定向Websocket

2024-09-24 00:35:17 发布

您现在位置:Python中文网/ 问答频道 /正文

Websocket重定向

我有两个服务,一个是websocket服务器,用于实时转录,但客户端只能连接第一个。我想做的是在下图中: ws_redirect

我查看了文档,最接近的是RedirectResponse section

from fastapi import FastAPI
from fastapi.responses import RedirectResponse

app = FastAPI()


@app.get("/typer")
### Websocket Redirect
I have two services, one have a websocket server on it for live transcription , but the client can only connect with the first
async def read_typer():
    return RedirectResponse("https://typer.tiangolo.com")

我会安抚任何帮助。 谢谢大家!


Tags: thefrom文档import服务器app客户端have