馃悰 Type annotations for headers in HTTPException
declare Any
as values but only accept str
#9649
Closed
9 tasks done
Labels
bug
Something isn't working
馃悰 Type annotations for headers in
HTTPException
declareAny
as values but only acceptstr
.Fixed in #9648
Discussed in #8562
Originally posted by DorAbu January 20, 2022
First Check
Commit to Help
Example Code
Description
In HTTPException object signature (attached below 1.), headers type hint is Optional[Dict[str, Any]].
But for example, when Dict[str, int] is given as in the "example code" section, the implementation in Starlette will raise an exception - AttributeError: 'int' object has no attribute 'encode' (attached below 2.).
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 System
Windows
Operating System Details
No response
FastAPI Version
0.70.1
Python Version
3.8.9 (tags/v3.8.9:a743f81, Apr 6 2021, 14:02:34) [MSC v.1928 64 bit (AMD64)]
Additional Context
starlette==0.16.0
The text was updated successfully, but these errors were encountered: