我在登录后一直收到这个错误,不知道为什么。请帮忙
@app.post("/login")
def Login(response: Response,credentials: HTTPBasicCredentials = Depends(HTTPBasic())):
correct_username = secrets.compare_digest(credentials.username, "root")
correct_password = secrets.compare_digest(credentials.password, "root")
if (correct_username and correct_password):
response.status_code = 302
response.headers["Location"] = "/welcome"
return response
@app.get("/welcome")
def welcome():
return {"message": "Hello"}
当我尝试使用/docs登录时,在键入正确的用户名和密码后,我从uvicorn获得服务器错误:
File ".\main.py", line 82, in Login
response.headers["Location"] = "/welcome"
AttributeError: 'Response' object has no attribute 'headers'
你检查进口了吗?它应该是
from fastapi import Response
我的代码中有一个类似的代码段,它与此导入和当前的fastapi版本一起工作相关问题 更多 >
编程相关推荐