Why am I getting Exception Error: 'Field' object has no attribute '__dir__' when uploading images

100 Views Asked by At

I recently 'upgraded' my web2py version to the latest version (2.27.1) but i've forgotten the previous version. I upgraded on the admin page by clicking on the button labeled Check for upgrades on a live app hosted on pythonanywhere.com. Now suddenly when i try to submit forms with upload attributes Field('logo', 'upload', label=SPAN('Your company logo')) I get this error: Field object has no attribute '_ _ dir _ _'. Somewhere somehow the image upload functionality has been disrupted. Before this web2py upgrade upload worked properly. Is there a way I can fix this, below is the Traceback & some error details I get from this error. If there is anymore information I can submit to help my request please let me know.

Traceback

Traceback (most recent call last):
  File "/home/myapp/web2py/gluon/restricted.py", line 219, in restricted
    exec(ccode, environment)
  File "/home/myapp/web2py/applications/init/controllers/default.py", line 920, in <module>
  File "/home/myapp/web2py/gluon/globals.py", line 463, in <lambda>
    self._caller = lambda f: f()
  File "/home/myapp/web2py/applications/init/controllers/default.py", line 315, in business_registration
    if form.process().accepted:
  File "/home/myapp/web2py/gluon/html.py", line 2410, in process
    self.validate(**kwargs)
  File "/home/myapp/web2py/gluon/html.py", line 2349, in validate
    if self.accepts(**kwargs):
  File "/home/myapp/web2py/gluon/sqlhtml.py", line 2132, in accepts
    source_file, original_filename, field.uploadfolder
  File "/home/myapp/web2py/gluon/packages/dal/pydal/objects.py", line 2075, in store
    self._tablename if '_tablename' in self.__dir__() and self._tablename else 'no_table',
AttributeError: 'Field' object has no attribute '__dir__'

Function argument list

filename='Kivy Documentation.pdf', path='/home/myapp/web2py/applications/init/static/business_docs')

Code listing

        m = re.search(REGEX_UPLOAD_EXTENSION, filename)
        extension = m and m.group(1) or "txt"
        uuid_key = self._db.uuid().replace("-", "")[-16:] if self._db else uuidstr()
        encoded_filename = to_native(base64.urlsafe_b64encode(to_bytes(filename)))
        newfilename = "%s.%s.%s.%s" % (
            self._tablename if '_tablename' in self.__dir__() and self._tablename else 'no_table',
            self.name,
            uuid_key,
            encoded_filename,
        )

In file: /home/myapp/web2py/applications/init/controllers/appadmin.py

"/home/myapp/web2py/applications/init/controllers/appadmin.py", line 7>
1

There are 1 best solutions below

0
Bruce Young On

I got this error when I moved from Python 2.7 to 3.7 I ad to use the python 3 version of web2py, and upgrade wsgi I had to uninstall python2-mod_wsgi.x86_64 and install python3-mod_wsgi.x86_64 Check your version or Python (Running on Apache/2.4.58 () OpenSSL/1.0.2k-fips mod_wsgi/3.4 Python/3.7.16, Python 3.7.16)