-
First Check
Commit to Help
Example Codefrom fastapi import FastAPI, HTTPException
app = FastAPI()
@app.get("/")
async def root():
raise HTTPException(
status_code=503,
detail=f"The server is not ready to handle the request, due to ...",
headers={"Retry-After": 20}
) DescriptionIn HTTPException object signature (attached below 1.), headers type hint is Optional[Dict[str, Any]]. Seems that Starlette implementation expects Optional[Dict[str, str]] type hint, FastAPI may resolve it by converting the values of the headers to strings. Operating SystemWindows Operating System DetailsNo response FastAPI Version0.70.1 Python Version3.8.9 (tags/v3.8.9:a743f81, Apr 6 2021, 14:02:34) [MSC v.1928 64 bit (AMD64)] Additional Contextstarlette==0.16.0 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
I am a bit confused. This function signature below clearly shows that it is supposed to be a |
Beta Was this translation helpful? Give feedback.
-
Indeed! This is wrong. The type annotation should define that it expects a The fix will be available in the next version, released in a few hours (the current version is |
Beta Was this translation helpful? Give feedback.
Indeed! This is wrong. The type annotation should define that it expects a
str
as value. I just fixed it in #9648The fix will be available in the next version, released in a few hours (the current version is
0.96.0
).