Not able to handle URL-encoded GET parameters - Response code 422 - Expected?
See original GitHub issueIs it expected that FastAPI cannot handle URL-encoded GET parameters? I searched the docs and via google but couldn’t find any hints why this is or how to change the behaviour.
See the example below. I’m trying to pass float numbers as GET parameters with the .
being URL-encoded. I’m getting the response that the number isn’t a valid float.
Example
from pydantic import BaseModel
from fastapi import FastAPI
app = FastAPI()
class LongitudinalDiameterAndQuantity(BaseModel):
diameter: float
quantity_a: float
quantity_b: float
@app.get("/column/longitudinal/diameter_quantity", response_model=LongitudinalDiameterAndQuantity)
def read_root(As: float, a: float, b: float):
# TODO: Feed parameters into ML model and get results
return LongitudinalDiameterAndQuantity(diameter=As, quantity_a=a, quantity_b=b)
Description
Non-URL-Encoded - working
URL: http://localhost:8000/column/longitudinal/diameter_quantity?As=1.2&a=1.2&b=1.2
As expected: Response code 200, content: {"diameter":1.2,"quantity_a":1.2,"quantity_b":1.2}
URL-Encoded - not working
URL: http://localhost:8000/column/longitudinal/diameter_quantity?As=1%2C2&a=1%2C2&b=1%2C2
Not expected: Response code 422, content:
{
"detail":[
{
"loc":[
"query",
"As"
],
"msg":"value is not a valid float",
"type":"type_error.float"
},
{
"loc":[
"query",
"a"
],
"msg":"value is not a valid float",
"type":"type_error.float"
},
{
"loc":[
"query",
"b"
],
"msg":"value is not a valid float",
"type":"type_error.float"
}
]
}
Environment
- OS: Windows 10 64 bit
- Python: 3.8.3
- FastAPI: 0.61.1
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
How To Fix the HTTP 422 Error - Kinsta
Error 422 is an HTTP code that tells you that the server can't process your request, although it understands it. The full name...
Read more >FastApi 422 Unprocessable Entity, on authentication, how to fix?
422 indicates that one of the required parameters to the FastAPI endpoint is missing (i.e. it doesn't match the expected input format). The ......
Read more >http - Is a 422 response ever appropriate for a GET request?
The HyperText Transfer Protocol (HTTP) 422 Unprocessable Entity response status code indicates that the server understands the content type of ...
Read more >HTTP Status Codes For Invalid Data: 400 vs. 422 - Ben Nadel
HTTP status code 422 feels like a much more appropriate response for situations where the data is understood, but is still not valid....
Read more >422 Unprocessable Entity - HTTP - MDN Web Docs
The HyperText Transfer Protocol (HTTP) 422 Unprocessable Entity response status code indicates that the server understands the content type ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Haha, no problem 😄
Thanks for the hint regarding xxd 👍
Thanks for the help here @ycd ! 👏 🙇
Thanks for reporting back and closing the issue @MarcelKr 👍