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

Change to Request.get_json() in Werkzeug 2.1.0 breaks Argument.parse() #422

Closed
stacywsmith opened this issue Mar 29, 2022 · 2 comments · Fixed by #423
Closed

Change to Request.get_json() in Werkzeug 2.1.0 breaks Argument.parse() #422

stacywsmith opened this issue Mar 29, 2022 · 2 comments · Fixed by #423
Labels
bug Something isn't working

Comments

@stacywsmith
Copy link
Contributor

pallets/werkzeug#2339 changed the behavior of Request.get_json()
and the Request.json property to raise a BadRequest if Request.get_json() is called, or the Request.json property
is accessed and the content type is not application/json.

Repro Steps (if applicable)

  1. Install Werkzeug >= 2.1.0
  2. Call parse() on an Argument instance that is from a Request that is NOT content type application/json

Expected Behavior

Argument should be parsed from the query string.

Actual Behavior

raises

werkzeug.exceptions.BadRequest: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand.

Error Messages/Stack Trace

  File "./rest/api/v1/endpoints/services.py", line 207, in get
    args = SERVICES_PARSER.parse_args()
  File "./.tox/py38/lib/python3.8/site-packages/flask_restx/reqparse.py", line 386, in parse_args
    value, found = arg.parse(req, self.bundle_errors)
  File "./.tox/py38/lib/python3.8/site-packages/flask_restx/reqparse.py", line 215, in parse
    source = self.source(request)
  File "./.tox/py38/lib/python3.8/site-packages/flask_restx/reqparse.py", line 149, in source
    value = getattr(request, l, None)
  File "./.tox/py38/lib/python3.8/site-packages/werkzeug/wrappers/request.py", line 540, in json
    return self.get_json()
  File "./.tox/py38/lib/python3.8/site-packages/werkzeug/wrappers/request.py", line 571, in get_json
    return self.on_json_loading_failed(None)
  File "./.tox/py38/lib/python3.8/site-packages/flask/wrappers.py", line 133, in on_json_loading_failed
    raise BadRequest() from e
werkzeug.exceptions.BadRequest: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand.

Environment

  • Python version: CPython 3.8.12
  • Flask version: 2.1.0
  • Flask-RESTX version: 0.5.1
  • Other installed Flask extensions: N/A
  • Werkzeug: 2.1.0
@deamos
Copy link

deamos commented Jun 21, 2022

Any movement on this issue? I've run into this, and it has been blocking a long change of much needed dependency updates. For now, I've been able to find a work around by adding the code from the following link:
pallets/flask#4552 (comment)

@Ryu-CZ
Copy link
Contributor

Ryu-CZ commented Aug 31, 2022

I fixed flask-restx/flask_restx/reqparse.py in my restx-monkey patches. I hope it will help you, feedback is welcome. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants