REST API POST Return non-dict creates an obscure error message

30 views
Skip to first unread message

James Burke

unread,
Nov 21, 2015, 3:17:39 AM11/21/15
to web2py-users
I recently upgraded an application on Pythonanywhere.com to: Version 2.12.3-stable+timestamp.2015.08.19.00.18.03

Part of the application uses jQuery to post files to a web2py REST API. After the upgrade I noticed that I kept getting this unhelpful error 500 message:

PythonAnywhere: something went wrong :-(

Looking at the server error log seemed to point to a DAL error...:

2015-11-21 07:11:07,012 :Traceback (most recent call last):
2015-11-21 07:11:07,013 :  File "/bin/user_wsgi_wrapper.py", line 134, in __call__
2015-11-21 07:11:07,013 :    self.error_log_file.logger.exception("Error running WSGI application")
2015-11-21 07:11:07,013 :  File "/usr/lib/python2.7/logging/__init__.py", line 1185, in exception
2015-11-21 07:11:07,014 :    self.error(msg, *args, **kwargs)
2015-11-21 07:11:07,014 :  File "/usr/lib/python2.7/logging/__init__.py", line 1178, in error
2015-11-21 07:11:07,014 :    self._log(ERROR, msg, args, **kwargs)
2015-11-21 07:11:07,014 :  File "/usr/lib/python2.7/logging/__init__.py", line 1270, in _log
2015-11-21 07:11:07,015 :    record = self.makeRecord(self.name, level, fn, lno, msg, args, exc_info, func, extra)
2015-11-21 07:11:07,015 :  File "/usr/lib/python2.7/logging/__init__.py", line 1244, in makeRecord
2015-11-21 07:11:07,015 :    rv = LogRecord(name, level, fn, lno, msg, args, exc_info, func)
2015-11-21 07:11:07,015 :  File "/usr/lib/python2.7/logging/__init__.py", line 284, in __init__
2015-11-21 07:11:07,016 :    self.threadName = threading.current_thread().name
2015-11-21 07:11:07,016 :  File "/usr/lib/python2.7/threading.py", line 1160, in currentThread
2015-11-21 07:11:07,016 :    return _active[_get_ident()]
2015-11-21 07:11:07,016 :  File "/bin/user_wsgi_wrapper.py", line 127, in __call__
2015-11-21 07:11:07,016 :    for response in app_iterator:
2015-11-21 07:11:07,016 :  File "/home/web2py2/gluon/packages/dal/pydal/helpers/classes.py", line 133, in __getitem__
2015-11-21 07:11:07,020 :    self.__allocate()
2015-11-21 07:11:07,020 :  File "/home/web2py2/gluon/packages/dal/pydal/helpers/classes.py", line 102, in __allocate
2015-11-21 07:11:07,021 :    self._record = self._table[long(self)]
2015-11-21 07:11:07,021 :  File "/home/web2py2/gluon/packages/dal/pydal/objects.py", line 505, in __getitem__
2015-11-21 07:11:07,022 :    orderby_on_limitby=False
2015-11-21 07:11:07,022 :  File "/home/web2py2/gluon/packages/dal/pydal/objects.py", line 2002, in select
2015-11-21 07:11:07,023 :    return adapter.select(self.query,fields,attributes)
2015-11-21 07:11:07,023 :  File "/home/web2py2/gluon/packages/dal/pydal/adapters/base.py", line 1286, in select
2015-11-21 07:11:07,025 :    return self._select_aux(sql,fields,attributes)
2015-11-21 07:11:07,025 :  File "/home/web2py2/gluon/packages/dal/pydal/adapters/base.py", line 1243, in _select_aux
2015-11-21 07:11:07,026 :    self.execute(sql)
2015-11-21 07:11:07,026 :  File "/home/web2py2/gluon/packages/dal/pydal/adapters/base.py", line 1378, in execute
2015-11-21 07:11:07,027 :    return self.log_execute(*a, **b)
2015-11-21 07:11:07,027 :  File "/home/web2py2/gluon/packages/dal/pydal/adapters/base.py", line 1363, in log_execute
2015-11-21 07:11:07,028 :    if not self.connection: raise ValueError(a[0])
2015-11-21 07:11:07,028 :ValueError: SELECT  workspace.id, workspace.repository, workspace.name, workspace.file, workspace.created_date, workspace.modified_date, workspace.company_id FROM workspace WHERE (workspace.id = 17) LIMIT 1 OFFSET 0;

It wasn't until I disabled the return statement in the REST API POST function that I identified the cause of the error.

The issue seems to have been that I was returning an integer value, as apposed to JSON/dict etc as mentioned in this thread:

I also tested on Rocket server - it is a bit more informative:

ERROR:Rocket.Errors.Thread-2:Traceback (most recent call last):

  File "/home/web2py2/gluon/rocket.py", line 1337, in run
    self.run_app(conn)

  File "/home/web2py2/gluon/rocket.py", line 1868, in run_app
    output.close()

TypeError: 'NoneType' object is not callable

Reply all
Reply to author
Forward
0 new messages