jsonify() behavior undefined when passed both args and kwargs
Package:
flask
56479

Exception Class:
TypeError
Raise code
separators = (",", ":")
if current_app.config["JSONIFY_PRETTYPRINT_REGULAR"] or current_app.debug:
indent = 2
separators = (", ", ": ")
if args and kwargs:
raise TypeError("jsonify() behavior undefined when passed both args and kwargs")
elif len(args) == 1: # single args are passed directly to dumps()
data = args[0]
else:
data = args or kwargs
return current_app.response_class(
f"{dumps(data, indent=indent, separators=separators)}\n",
🙏 Scream for help to Ukraine
Today, 3rd July 2022, Russia continues bombing and firing Ukraine. Don't trust Russia, they are bombing us and brazenly lying in same time they are not doing this 😠, civilians and children are dying too!
We are screaming and asking exactly you to help us, we want to survive, our families, children, older ones.
Please spread the information, and ask your governemnt to stop Russia by any means. We promise to work extrahard after survival to make the world safer place for all.
Please spread the information, and ask your governemnt to stop Russia by any means. We promise to work extrahard after survival to make the world safer place for all.
Links to the raise (1)
https://github.com/pallets/flask/blob/83f7efa04708a22c9701488f0f29b59c2b756bef/src/flask/json/__init__.py#L341Ways to fix
Arguments and keyword arguments should not be passed at the same time to jsonify.
How to reproduce:
from flask import Flask, jsonify
app = Flask(__name__)
@app.route("/")
def index():
return jsonify("text", i="test")
app.run()
Code with fix
from flask import Flask, jsonify
app = Flask(__name__)
@app.route("/")
def index():
return jsonify(j="text", i="test") #<-- pass only arg or kwarg, not both
app.run()
Add a possible fix
Please authorize to post fix