FastAPI 中的端点GET返回正确的结果,但405 method not allowed在curl -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)
我们如何从另一个子生成器产生,但要进行转换/处理?
例如:在下面的代码中, 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)