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

Failed get_json #1786

Closed
yi719 opened this issue Apr 20, 2016 · 7 comments
Closed

Failed get_json #1786

yi719 opened this issue Apr 20, 2016 · 7 comments

Comments

@yi719
Copy link

yi719 commented Apr 20, 2016

hi, we find a strange error, sometime request.get_json(force=True) will fail.
And,

data = _get_data(self, cache)

data here is http header in string instead of http body!!

@RonnyPfannschmidt
Copy link
Contributor

please provide more context, like what wsgi gateway is being used, what versions are involved and get us some proactive information

because what you wrote cannot possibly help in guessing/comprehending what's wrong on your side

@yi719
Copy link
Author

yi719 commented Apr 20, 2016

@RonnyPfannschmidt Thank you for reminding me.
we use
gunicorn==19.3.0
Flask==0.10.1
gevent==1.1.0

behind nginx/1.4.6

we see errors from sentry like
flask.wrappers in on_json_loading_failed BadRequest: 400: Bad Request

085d2019-0284-465d-a154-9f1c09df5474

@ThiefMaster
Copy link
Member

Well that looks a lot like you are sending data that's not valid JSON.

@RonnyPfannschmidt
Copy link
Contributor

at first glance this looks like a complete http message is being sent as body of a request, this could be a bad client, does this happen from your tests or is the source a certain customer/user

@yi719
Copy link
Author

yi719 commented Apr 20, 2016

this only occurs Occasionally in one of our API to which client post analytics in batch mode.
just wondering if it's caused by werkzeug parsing HTTP or request modified by some ISP's proxy

@davidism
Copy link
Member

davidism commented Apr 20, 2016

The data being sent is not valid JSON. Whatever is causing that is the problem, but it's not Flask. If you do discover a bug in Flask, please provide enough information for us to reproduce the issue.

@jaketeater
Copy link

jaketeater commented Aug 15, 2017

I also encountered this problem. In case it would help anyone else, I found that with sentry commented out, the get_json() worked. However, with the exact same request while using sentry it failed every time.

Seems to be an issue with sentry?

Edit:

Figured it out, I didn't have the content type set in my jquery requests. I was using get_json(force=True). Which was fine until I added sentry. Apparently the behavior of get_json changes when you use sentry.

To fix I just added this to my jquery ajax request:

contentType: "application/json"

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants