python-restx / flask-restx

Fork of Flask-RESTPlus: Fully featured framework for fast, easy and documented API development with Flask
https://flask-restx.readthedocs.io/en/latest/
Other
2.16k stars 335 forks source link

ValueError: too many values to unpack (expected 2) for requestparser #224

Open BHAUTIK04 opened 4 years ago

BHAUTIK04 commented 4 years ago

I was using Flask-restplus and migrated to flask-restx. But when I parse a request params, I am getting this error. Suddenly started this error and Same error i was getting for flask-restplus too.

args = self.parser.parse_args() File "/dv/virtualenvs-apps/env/lib/python3.6/site-packages/flask_restx/reqparse.py", line 387, in parse_args value, found = arg.parse(req, self.bundle_errors) File "/dv/virtualenvs-apps/env/lib/python3.6/site-packages/flask_restx/reqparse.py", line 215, in parse source = self.source(request) File "/dv/virtualenvs-apps/env/lib/python3.6/site-packages/flask_restx/reqparse.py", line 153, in source values.update(value) File "/dv/virtualenvs-apps/env/lib/python3.6/site-packages/werkzeug/datastructures.py", line 627, in update for key, value in iter_multi_items(other_dict): ValueError: too many values to unpack (expected 2)

Any help will be highly appreciated.

jainavana commented 3 years ago

I am also seeing this error specifically when I am parsing an list of objects inrequest.json. For instance, in a scenario where I accept the following body (an array of json objects)

[{ "key1":"value1", "key2":"value2", "key3":"value3" }]

and call parser.parse_args to retrieve my query params, I am encountering the error. However, if I limit my json objects to only including two key-value pairings instead of three i.e.

[{ "key1":"value1", "key2":"value2" }] then theiter_mutli_items function does not throw a problem.

Another thing I noticed is that this error is brought about if I need to use the parser to parse the arguments passed alongside. If, I needed to simply pass a request body, I would not be facing this issue.

sleiss commented 3 years ago

I can confirm the findings of @jainavana. Do you know if this bug was introduced in a specific version?

sleiss commented 3 years ago

@BHAUTIK04 @jainavana I was able to solve this issue by myself: I added the location='args' value to the arguments that are part of the arguments, so e.g. of parser.add_argument('language', type=str, help='Language of the text') I now have parser.add_argument('language', type=str, help='Language of the text', location='args')

This solves the issue, at least for me.