potion
potion copied to clipboard
Application/json requests to Potion routes fails
I have a user resource registered with potion:
class UserResource(ModelResource):
class Meta:
model = User
class Schema:
organization = fields.ToOne('organization')
@Route.GET
def me(self) -> fields.Integer:
print('Never get's here' with application/json)
return 1
If I query /api/user
with either Content-Type: application/json
or application/text
I get a list of users as expected.
If I query /api/user/me
with Content-Type: application/text
I get back 1
as expected.
If I query it with Content-Type: application/json
I get:
{
"message": "Failed to decode JSON object: Expecting value: line 1 column 1 (char 0)",
"status": 400
}
I use Postman to tests the requests. I stripped out all decorators for authentication for the sake of this test. I've tried with Flask 0.10 and Flask 0.11 (the above mentioned error is with Flask 0.11). With 0.10 I had the same issue with a less verbose message. Python 3.4
At first look, this would make sense. If you send a GET request you will send an empty request body, but "" (empty message) is not valid JSON. We could silently ignore JSON in GET requests. What solution do you propose?
(To clarify: sending an empty message with Content-Type: application/json is indeed an invalid request)
I wouldn't silently ignore. Maybe a more meaningful message then Expecting value: line 1 column 1 (char 0)
? Maybe one specific for the empty JSON request?
Remove the old one Request in POSTMAN Collection and create new one.
I'm running into the same issue when I try to make a put request using Postman with Context-Type application/json. All other endpoints which use the same route and same header work (get, post, delete) however put does not work.
I initially removed the old request and made a new one. That fixed it the first time. However, that only worked once. Now I'm running into this same error indefinitely.
{ "message": "Failed to decode JSON object: Expecting value: line 1 column 1 (char 0)" }
GUYS OK I THINK I FIGURED IT OUT
You need to also have the Content-Length header enabled. Otherwise you'll get this error.