question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Not able to handle URL-encoded GET parameters - Response code 422 - Expected?

See original GitHub issue

Is 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:closed
  • Created 3 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
MarcelKrcommented, Sep 3, 2020

Ooooooooooooh. I missunderstood the whole question

Haha, no problem 😄

Thanks for the hint regarding xxd 👍

0reactions
tiangolocommented, Dec 26, 2020

Thanks for the help here @ycd ! 👏 🙇

Thanks for reporting back and closing the issue @MarcelKr 👍

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found