小编toi*_*ing的帖子

FastAPI GET 端点返回“405 method not allowed”响应

FastAPI 中的端点GET返回正确的结果,但405 method not allowedcurl -I使用时返回。所有GET端点都会发生这种情况。因此,应用程序正在运行,但负载均衡器对应用程序的运行状况检查失败。

有什么建议可能是错误的吗?

代码

@app.get('/health')
async def health():
    """
    Returns health status
    """
    return JSONResponse({'status': 'ok'})
Run Code Online (Sandbox Code Playgroud)

结果

curl http://172.xx.xx.xx:8080
Run Code Online (Sandbox Code Playgroud)

返回标头

curl -I http://172.xx.xx.xx:8080
Run Code Online (Sandbox Code Playgroud)

python rest http-status-code-405 fastapi

5
推荐指数
1
解决办法
7068
查看次数

“从”另一台发电机“产出”,但经过处理

我们如何从另一个子生成器产生,但要进行转换/处理?

例如:在下面的代码中, main_gen 在使用 f(x) 转换后产生 x

def f(x):
   return 2*x

def main_gen():
   for x in sub_gen():
      yield f(x)
Run Code Online (Sandbox Code Playgroud)

这可以用yield from替换吗?如果可以,如何替换?

def main_gen():
     yield from ***
Run Code Online (Sandbox Code Playgroud)

python yield generator python-3.x yield-from

4
推荐指数
1
解决办法
59
查看次数