Forums

InterfaceError: (0, ''), 500 Internal Server Error

Hi, I am new to python and flask. I am using it for my school project. So I successfully uploaded my files and it runs when I hit that big green button on my Web tab. However, after few minutes the site crashes saying there is an internal server error. And when I go to the error log, I see this:

2018-11-10 14:30:43,167: Exception on /main [GET]
Traceback (most recent call last):
  File "/home/dongjae93/.virtualenvs/my-virtualenv/local/lib/python2.7/site-packages/flask/app.py", line 2292, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/dongjae93/.virtualenvs/my-virtualenv/local/lib/python2.7/site-packages/flask/app.py", line 1815, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/dongjae93/.virtualenvs/my-virtualenv/local/lib/python2.7/site-packages/flask/app.py", line 1718, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/dongjae93/.virtualenvs/my-virtualenv/local/lib/python2.7/site-packages/flask/app.py", line 1813, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/dongjae93/.virtualenvs/my-virtualenv/local/lib/python2.7/site-packages/flask/app.py", line 1799, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/dongjae93/v2/app.py", line 956, in main
    uid = getUserIdFromEmail(flask_login.current_user.id)
  File "/home/dongjae93/.virtualenvs/my-virtualenv/local/lib/python2.7/site-packages/werkzeug/local.py", line 347, in __getattr__
    return getattr(self._get_current_object(), name)
  File "/home/dongjae93/.virtualenvs/my-virtualenv/local/lib/python2.7/site-packages/werkzeug/local.py", line 306, in _get_current_object
    return self.__local()
  File "/home/dongjae93/.virtualenvs/my-virtualenv/local/lib/python2.7/site-packages/flask_login/utils.py", line 26, in <lambda>
    current_user = LocalProxy(lambda: _get_user())
  File "/home/dongjae93/.virtualenvs/my-virtualenv/local/lib/python2.7/site-packages/flask_login/utils.py", line 335, in _get_user
    current_app.login_manager._load_user()
  File "/home/dongjae93/.virtualenvs/my-virtualenv/local/lib/python2.7/site-packages/flask_login/login_manager.py", line 359, in _load_user
    return self.reload_user()
  File "/home/dongjae93/.virtualenvs/my-virtualenv/local/lib/python2.7/site-packages/flask_login/login_manager.py", line 321, in reload_user
    user = self.user_callback(user_id)
  File "/home/dongjae93/v2/app.py", line 65, in user_loader
    users = getUserList()
  File "/home/dongjae93/v2/app.py", line 56, in getUserList
    cursor.execute("SELECT email from users")
  File "/home/dongjae93/.virtualenvs/my-virtualenv/local/lib/python2.7/site-packages/pymysql/cursors.py", line 170, in execute
    result = self._query(query)
  File "/home/dongjae93/.virtualenvs/my-virtualenv/local/lib/python2.7/site-packages/pymysql/cursors.py", line 328, in _query
    conn.query(q)
  File "/home/dongjae93/.virtualenvs/my-virtualenv/local/lib/python2.7/site-packages/pymysql/connections.py", line 515, in query
    self._execute_command(COMMAND.COM_QUERY, sql)
  File "/home/dongjae93/.virtualenvs/my-virtualenv/local/lib/python2.7/site-packages/pymysql/connections.py", line 745, in _execute_command
    raise err.InterfaceError("(0, '')")
InterfaceError: (0, '')

If I refresh the webapp by clicking the green button, it seems to work fine for another few minutes. But it crashes again with the same error log.

When I run this on my local machine, it works fine without any problem :P

If anyone could help me that'd be great! Thanks in advance :)

I see in that unformatted traceback that you're trying to query a MySQL server. If it works for a bit, and then stops, I'm guessing that you start the connection when your web app starts and then use that same connection for each new request. When the connection times out (after 5 min), then your app fails. Change your code so that you open a new connection in every request, or so that, if the connection is not working, it re-connects.

I see in that unformatted traceback that you're trying to query a MySQL server. If it works for a bit, and then stops, I'm guessing that you start the connection when your web app starts and then use that same connection for each new request. When the connection times out (after 5 min), then your app fails. Change your code so that you open a new connection in every request, or so that, if the connection is not working, it re-connects.

Ah okay so I tried making cursors locally and then closed them before I return a vale from a function. Now the web does not crash but some of my functions are not working properly :/

I make function calls inside of multiple function. Could that be a problem?

how are you managing your db connections? are you using something like sqlalchemy?