Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

There was an error parsing the body #110

Answered by eadwinCode
bobwatcherx asked this question in Q&A
Discussion options

i follow you tutorial . but i have error . i want get form input openAPI post method

https://eadwincode.github.io/ellar/overview/controllers/#enabling-openapi-docs

code

schemas.py

from ellar.common import Serializer
from pydantic import Field
class CreateCarSerializer(Serializer):
 name: str
 year: int = Field(..., gt=0)
 model: str
class CarListFilter(Serializer):
 offset: int = 1
 limit: int = 10
class CarSerializer(Serializer):
 id: str
 name: str
 year: int
 model: str

controllers.py

from ellar.common import Body, Controller, ControllerBase, delete, get, post, put, Query
from ellar.core import Request
from .schemas import CreateCarSerializer, CarListFilter
@Controller
class CatsController(ControllerBase):
 @post()
 async def create(self, payload: CreateCarSerializer = Body()):
 result = payload.dict()
 result.update(message='This action adds a new car')
 return result
 @put('/{car_id:str}')
 async def update(self, car_id: str, payload: CreateCarSerializer = Body()):
 result = payload.dict()
 result.update(message=f'This action updated #{car_id} car resource')
 return result
 @get('/{car_id:str}')
 async def get_one(self, car_id: str):
 return f"This action returns a #{car_id} car"
 @delete('/{car_id:str}')
 async def delete(self, car_id: str):
 return f"This action removes a #{car_id} car"
You must be logged in to vote

Everything works fine with the code you posted here.

However, there is no form field on the code you shared. And all Body() fields accept application/json body format.
checkout form inputs doc here

Replies: 2 comments 2 replies

Comment options

error message

{
"detail": "There was an error parsing the body",
"status_code": 400
}

You must be logged in to vote
2 replies
Comment options

Everything works fine with the code you posted here.

However, there is no form field on the code you shared. And all Body() fields accept application/json body format.
checkout form inputs doc here

Answer selected by eadwinCode
Comment options

Also, it would be helpful if you can share the log that generated this error. Thanks

Comment options

@bobwatcherx Thanks... I will look at this

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /