Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Application/json requests to Potion routes fails #94

Open
Alain1405 opened this issue Jul 28, 2016 · 6 comments
Open

Application/json requests to Potion routes fails #94

Alain1405 opened this issue Jul 28, 2016 · 6 comments

Comments

@Alain1405
Copy link
Contributor

Alain1405 commented Jul 28, 2016

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

@lyschoening
Copy link
Contributor

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
Copy link
Contributor

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

@Alain1405
Copy link
Contributor Author

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?

@Jeevan-bhandari-git
Copy link

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

@SandysPappy
Copy link

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
Copy link

GUYS OK I THINK I FIGURED IT OUT

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants