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 to decode JSON object: Expecting value: line 1 column 1 (char 0) - Werkzeug .2.1.x #2386

Closed
pasolid opened this issue Apr 10, 2022 · 4 comments

Comments

@pasolid
Copy link

pasolid commented Apr 10, 2022

I'm encountering this error since version 2.1.x.
All I do is to call GET HTTP://localhost:5000/api/some/path, with an empty body and no parameters in the request.

This is the curl request:

curl --location --request GET 'http://localhost:5000/api/some/path' \
--header 'Content-Type: application/json; charset=utf-8'

With Werkzeug version 2.0.3 everything is running fine, no errors and the response is 200

Environment:

  • Python version: 3.7.12
  • Flask: 2.1.1
  • Flask-Parameter-Validation: 2.0.6
  • Flask-WTF: 1.0.1
  • Werkzeug version: 2.1.x
@davidism
Copy link
Member

I can't reproduce this issue with the information provided.

@pasolid
Copy link
Author

pasolid commented Apr 12, 2022

I can't reproduce this issue with the information provided.

Attaching the example project. I'm reproducing the issue just by switching between versions 2.0.3 to 2.1.1.

I also had next observation:

Version 2.0.3

  • Sending request W/O 'Content-Type: application/json; charset=utf-8' results in status 200:
[2022-04-13 02:27:33,184] INFO in main2: Test reached
127.0.0.1 - - [13/Apr/2022 02:27:33] "GET /test HTTP/1.1" 200 -
  • Sending request with 'Content-Type: application/json; charset=utf-8' results in status 400:
127.0.0.1 - - [13/Apr/2022 02:29:55] "GET /test HTTP/1.1" 400 -

And the response on the client's side is:
Failed to decode JSON object: Expecting value: line 1 column 1 (char 0)

Version 2.1.1

  • Sending request W/O 'Content-Type: application/json; charset=utf-8' results in status 400 with message on the client's side:
    Did not attempt to load JSON data because the request Content-Type was not 'application/json'.

  • Sending request with 'Content-Type: application/json; charset=utf-8' also results in status 400 with message on the client's side:
    Failed to decode JSON object: Expecting value: line 1 column 1 (char 0)

# Extremely simple flask application
from flask import Flask
from flask_parameter_validation import ValidateParameters

app = Flask(__name__)


@app.route("/test", methods=['GET'])
@ValidateParameters()
def test():
    app.logger.info('Test reached')
    return 'Hello, world'


# When running the app directly through the Python command (use app.logger)
if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5001, debug=True)

I hope this will help

@davidism
Copy link
Member

I still can't reproduce, sending valid json is decoded correctly with the example provided.

@pasolid
Copy link
Author

pasolid commented Apr 19, 2022

I still can't reproduce, sending valid json is decoded correctly with the example provided.

Wait, what do you mean by sending valid JSON? This is GET request. The body of the request is empty. NO JSON should be sent. In the provided example it does not expect any json in request.

@app.route("/test", methods=['GET'])

Maybe this is the problem, that Werkzeug is expecting some json in the request which is not right behavior.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 4, 2022
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

2 participants