Forums

ValueError: too many values to unpack (expected 2)

Hi,

I have a python / flask app that works fine on a local machine though when deploying via PA I'm receiving the following error:

ValueError: too many values to unpack (expected 2)

The only line of code referenced in the error is: <td>{{ render_field(form.asset_category) }}</td> which on the local machine returns the single item from a list perfectly fine.

Any help is appreciated.

Full Traceback:

Traceback (most recent call last): File "/usr/lib/python3.7/site-packages/flask/app.py", line 2446, in wsgi_app response = self.full_dispatch_request() File "/usr/lib/python3.7/site-packages/flask/app.py", line 1951, in full_dispatch_request rv = self.handle_user_exception(e) File "/usr/lib/python3.7/site-packages/flask/app.py", line 1820, in handle_user_exception reraise(exc_type, exc_value, tb) File "/usr/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise raise value File "/usr/lib/python3.7/site-packages/flask/app.py", line 1949, in full_dispatch_request rv = self.dispatch_request() File "/usr/lib/python3.7/site-packages/flask/app.py", line 1935, in dispatch_request return self.view_functionsrule.endpoint File "/home/chrisbradd/lenders/flask_app.py", line 28, in index return render_template('first_app.html', form=form) File "/usr/lib/python3.7/site-packages/flask/templating.py", line 140, in render_template ctx.app, File "/usr/lib/python3.7/site-packages/flask/templating.py", line 120, in _render rv = template.render(context) File "/usr/lib/python3.7/site-packages/jinja2/asyncsupport.py", line 76, in render return original_render(self, args, kwargs) File "/usr/lib/python3.7/site-packages/jinja2/environment.py", line 1008, in render return self.environment.handle_exception(exc_info, True) File "/usr/lib/python3.7/site-packages/jinja2/environment.py", line 780, in handle_exception reraise(exc_type, exc_value, tb) File "/usr/lib/python3.7/site-packages/jinja2/_compat.py", line 37, in reraise raise value.with_traceback(tb) File "/home/chrisbradd/lenders/templates/first_app.html", line 70, in top-level template code <td>{{ render_field(form.asset_category) }}</td> File "/usr/lib/python3.7/site-packages/jinja2/runtime.py", line 574, in _invoke rv = self._func(arguments) File "/home/chrisbradd/lenders/templates/_formhelpers.html", line 21, in macro File "/usr/lib/python3.7/site-packages/jinja2/runtime.py", line 262, in call return obj(args, kwargs) File "/usr/lib/python3.7/site-packages/wtforms/fields/core.py", line 155, in call return self.meta.render_field(self, kwargs) File "/usr/lib/python3.7/site-packages/wtforms/meta.py", line 56, in render_field return field.widget(field, *render_kw) File "/usr/lib/python3.7/site-packages/wtforms/widgets/core.py", line 323, in __call for val, label, selected in field.iter_choices(): File "/usr/lib/python3.7/site-packages/wtforms/fields/core.py", line 454, in iter_choices for value, label in self.choices: ValueError: too many values to unpack (expected 2)

You probably have a package version mismatch somewhere. Check the versions of the packages that you have on your local machine and make sure that you're using the same versions on PythonAnywhere.

please im having exactly this same issue,somebody help! what is the way out??

Traceback (most recent call last): File "/usr/lib/python3.8/site-packages/flask/app.py", line 2446, in wsgi_app response = self.full_dispatch_request() File "/usr/lib/python3.8/site-packages/flask/app.py", line 1951, in full_dispatch_request rv = self.handle_user_exception(e) File "/usr/lib/python3.8/site-packages/flask/app.py", line 1820, in handle_user_exception reraise(exc_type, exc_value, tb) File "/usr/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise raise value File "/usr/lib/python3.8/site-packages/flask/app.py", line 1949, in full_dispatch_request rv = self.dispatch_request() File "/usr/lib/python3.8/site-packages/flask/app.py", line 1935, in dispatch_request return self.view_functionsrule.endpoint File "/home/mafking/mysite/flask_app.py", line 258, in reg return render_template('reg.html',regz=regz,opor=session.get('uname'),slide=slide) File "/usr/lib/python3.8/site-packages/flask/templating.py", line 137, in render_template return _render( File "/usr/lib/python3.8/site-packages/flask/templating.py", line 120, in _render rv = template.render(context) File "/usr/lib/python3.8/site-packages/jinja2/asyncsupport.py", line 76, in render return original_render(self, args, kwargs) File "/usr/lib/python3.8/site-packages/jinja2/environment.py", line 1008, in render return self.environment.handle_exception(exc_info, True) File "/usr/lib/python3.8/site-packages/jinja2/environment.py", line 780, in handle_exception reraise(exc_type, exc_value, tb) File "/usr/lib/python3.8/site-packages/jinja2/_compat.py", line 37, in reraise raise value.with_traceback(tb) File "/home/mafking/mysite/templates/reg.html", line 2, in <module> {% import 'bootstrap/wtf.html' as wtf %} File "/usr/lib/python3.8/site-packages/jinja2/environment.py", line 1005, in render return concat(self.root_render_func(self.new_context(vars))) File "/home/mafking/mysite/templates/reg.html", line 17, in root File "/home/mafking/mysite/templates/index.html", line 14, in root File "/usr/lib/python3.8/site-packages/flask_bootstrap/templates/bootstrap/base.html", line 10, in root <meta name="viewport" content="width=device-width, initial-scale=1.0"> File "/usr/lib/python3.8/site-packages/flask_bootstrap/templates/bootstrap/base.html", line 20, in block_doc {% block body -%} File "/usr/lib/python3.8/site-packages/flask_bootstrap/templates/bootstrap/base.html", line 39, in block_html File "/usr/lib/python3.8/site-packages/flask_bootstrap/templates/bootstrap/base.html", line 92, in block_body File "/home/mafking/mysite/templates/index.html", line 102, in block_content <button style="background-color:ghostwhite" class="btn btn-sm"><a style="color:tomato" href={{url_for("Crypto")}}><b>Crypto</b></a></button> File "/home/mafking/mysite/templates/reg.html", line 27, in block_main File "/usr/lib/python3.8/site-packages/jinja2/runtime.py", line 262, in call return __obj(args, kwargs) File "/usr/lib/python3.8/site-packages/jinja2/runtime.py", line 570, in call return self._invoke(arguments, autoescape) File "/usr/lib/python3.8/site-packages/jinja2/asyncsupport.py", line 110, in _invoke return original_invoke(self, arguments, autoescape) File "/usr/lib/python3.8/site-packages/jinja2/runtime.py", line 574, in _invoke rv = self._func(arguments) File "/usr/lib/python3.8/site-packages/flask_bootstrap/templates/bootstrap/wtf.html", line 495, in macro File "/usr/lib/python3.8/site-packages/jinja2/runtime.py", line 262, in call return __obj(args, kwargs) File "/usr/lib/python3.8/site-packages/jinja2/runtime.py", line 570, in call return self._invoke(arguments, autoescape) File "/usr/lib/python3.8/site-packages/jinja2/asyncsupport.py", line 110, in _invoke return original_invoke(self, arguments, autoescape) File "/usr/lib/python3.8/site-packages/jinja2/runtime.py", line 574, in _invoke rv = self._func(arguments) File "/usr/lib/python3.8/site-packages/flask_bootstrap/templates/bootstrap/wtf.html", line 342, in macro File "/usr/lib/python3.8/site-packages/jinja2/runtime.py", line 262, in call return __obj(args, kwargs) File "/usr/lib/python3.8/site-packages/wtforms/fields/core.py", line 155, in call return self.meta.render_field(self, kwargs) File "/usr/lib/python3.8/site-packages/wtforms/meta.py", line 56, in render_field return field.widget(field, render_kw) File "/usr/lib/python3.8/site-packages/wtforms/widgets/core.py", line 323, in call for val, label, selected in field.iter_choices(): File "/usr/lib/python3.8/site-packages/wtforms/fields/core.py", line 454, in iter_choices for value, label in self.choices: ValueError: too many values to unpack (expected 2)

You probably have a package version mismatch somewhere as Glenn pointed above

I have found my way around it.there was another selectfield I parsed with a list instead of a tuple. Didn't notice it on time.

Glad to hear that you made it work!