Forums

AttributeError: 'list' object has no attribute 'file_allowed'

Today I started using PythonAnywhere and am trying to get my app to run for the first time. I'm seeing an internal server error, and the log has a AttributeError: 'list' object has no attribute 'file_allowed' (see below).

I do not know Why I getting this error. Please help me to understand this problem.

Thanks.

2016-07-15 16:57:08,205 :Exception on /new_post [POST]
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1687, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1360, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1358, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1344, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/usr/local/lib/python2.7/dist-packages/flask_login.py", line 515, in decorated_view
    return fn(*args, **kwargs)
  File "/home/shuvanon/mysite/app.py", line 91, in post
    if form.validate_on_submit():
  File "/usr/local/lib/python2.7/dist-packages/flask_wtf/form.py", line 125, in validate_on_submit
    return self.is_submitted() and self.validate()
  File "/usr/local/lib/python2.7/dist-packages/wtforms/form.py", line 265, in validate
    return super(Form, self).validate(extra)
  File "/usr/local/lib/python2.7/dist-packages/wtforms/form.py", line 130, in validate
    if not field.validate(self, extra):
  File "/usr/local/lib/python2.7/dist-packages/wtforms/fields/core.py", line 176, in validate
    stop_validation = self._run_validation_chain(form, chain)
  File "/usr/local/lib/python2.7/dist-packages/wtforms/fields/core.py", line 196, in _run_validation_chain
    validator(form, self)
  File "/usr/local/lib/python2.7/dist-packages/flask_wtf/file.py", line 69, in __call__
    if not self.upload_set.file_allowed(field.data, field.data.filename):
AttributeError: 'list' object has no attribute 'file_allowed'

I can't really tell from that stack trace, but my guesses would be:

  • You're running a different version of Flask or WTForms than your code expects
  • You're trying to process a form that doesn't have uploads as if it does
  • You're trying to process a form that does have uploads as if it doesn't
  • Something really weird, like you're overwriting a property of an form object with a value it doesn't expect

Can you please see my code from your end and tell me more specifically. And I do not know how to adjust flask or other packages in pythonanywhere.
how can I use my version of flask or other packages?

I would suggest using a virtualenv. Here are instructions for creating one and installing modules into it. Then you can set your web app to use the virtualenv you've set up.