Form example doesn't work properly; Errors and incorrect rendering in Swagger #11602
Answered
by
JavierSanchezCastro
MasterGroosha
asked this question in
Questions
-
First Check
Commit to Help
Example Codefrom typing import Annotated
from fastapi import FastAPI, Form
app = FastAPI()
@app.post('/login')
def login(
username: str = Annotated[str, Form()],
password: str = Annotated[str, Form()],
):
return {'username': username} DescriptionFirst of all, when I open Swagger, instead of body parameters It "works", but that's not the result I expect. When I make request properly using Insomnia or Bruno: curl --request POST \
--url http://127.0.0.1:8000/login \
--header 'Content-Type: application/x-www-form-urlencoded' \
--header 'User-Agent: insomnia/2023.5.8' \
--data username=a \
--data password=b I get 500 Internal Server Error with the following traceback:
Operating SystemmacOS Operating System DetailsNo response FastAPI Version0.111.0 Pydantic Version2.7.1 Python VersionPython 3.9.19 Additional ContextAn example above is the same as in https://fastapi.tiangolo.com/tutorial/request-forms/ |
Beta Was this translation helpful? Give feedback.
Answered by
JavierSanchezCastro
May 19, 2024
Replies: 1 comment 1 reply
-
You're not using correctly Annonated, change to this: from typing import Annotated
from fastapi import FastAPI, Form
app = FastAPI()
@app.post('/login')
def login(
username: Annotated[str, Form()],
password: Annotated[str, Form()],
):
return {'username': username} |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
MasterGroosha
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You're not using correctly Annonated, change to this: