potion icon indicating copy to clipboard operation
potion copied to clipboard

Application/json requests to Potion routes fails

Open Alain1405 opened this issue 7 years ago • 6 comments

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

Alain1405 avatar Jul 28 '16 10:07 Alain1405

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?

lyschoening avatar Jul 28 '16 11:07 lyschoening

(To clarify: sending an empty message with Content-Type: application/json is indeed an invalid request)

lyschoening avatar Jul 28 '16 11:07 lyschoening

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?

Alain1405 avatar Sep 12 '16 09:09 Alain1405

Remove the old one Request in POSTMAN Collection and create new one.

Jeevan-bhandari-git avatar Aug 08 '20 10:08 Jeevan-bhandari-git

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)" }

SandysPappy avatar Jul 23 '21 03:07 SandysPappy

GUYS OK I THINK I FIGURED IT OUT

You need to also have the Content-Length header enabled. Otherwise you'll get this error.

SandysPappy avatar Jul 23 '21 04:07 SandysPappy