Forums

Resolving cryptic error message for Flask application

I've uploaded a Flask application and created a MySQLdb, I have my virtual environment set and can see the app.url_map when I look at the Flask application from the console. Still, I'm receiving the following error message in the log:

2015-06-29 03:26:47,513 :/usr/lib/python2.7/threading.py:1160: RuntimeWarning: tp_compare didn't return -1 or -2 for exception
2015-06-29 03:26:47,514 :  return _active[_get_ident()]
2015-06-29 03:26:47,511 :Error running WSGI application
None

I've been searching the forums for an answer to these cryptic log messages and I've come to believe the error is either 1) my environment variables are not correctly specified; 2) I don't have enough workers on the application. I doubt it's number 2. However, I believe I have my wsgi file set properly:

import os
import sys
os.environ['SECRET_KEY'] = 'my_precious'
os.environ['SQLALCHEMY_DATABASE_URI'] = 'mysql://wsankey:PASSWORD@mysql.server/wsankey$default'
os.environ['DEBUG'] = 'False'
os.environ['DEBUG_TB_ENABLED'] = 'False'
os.environ['STRIPE_SECRET_KEY'] = 'foo'
os.environ['STRIPE_PUBLISHABLE_KEY'] = 'bar'
#
path = '/home/wsankey/ppc_flask/'
if path not in sys.path:
sys.path.append(path)
#
from project import app as application
#application.config.from_object(os.environ['APP_SETTINGS'])
#basedir = os.path.abspath(os.path.dirname(__file__))

I'm currently at a loss for what to do. I can see the database in the console and interact with it (create the database, migrate it) with commands in my manage.py file. I've also removed the app.run() command from that manage.py file.

Any thoughts or recommendations? Maybe I'm setting my environment variables incorrectly?

I think those error mesages are nothing to worry about -- they happen when a client disconnects (maybe their internet connection drops out) -- so it's probably not affecting your users.

Unless you think you've seen specific problems, from the user perspective?

Sorry for being unclear: I haven't deployed my Flask app at all. I just keep seeing the default 'Something went wrong' main error page and the error logs aren't giving me much helpful information.

There is almost always helpful information in the error logs. Look for tracebacks and follow them to the error that caused them.

Yes, I've gone back and checked through the error, access, and server logs and haven't found any tracebacks that I haven't already fixed. This is what I'm encountering in the logs when I refresh:

Error:

2015-06-29 14:29:31,665 :/usr/lib/python2.7/threading.py:1160: RuntimeWarning: tp_compare didn't return -1 or -2 for exception
2015-06-29 14:29:31,665 :  return _active[_get_ident()]
2015-06-29 14:29:31,663 :Error running WSGI application
None
 2015-06-29 14:29:34,027 :Error running WSGI application
None

The access log is returning 500 errors and the server log returns the following:

 2015-06-29 14:29:29 Set PythonHome to /home/wsankey/ppc_flask/venv
 2015-06-29 14:29:29 *** Python threads support is disabled. You can enable it with --enable-    threads ***
2015-06-29 14:29:29 Python main interpreter initialized at 0xc989d0
2015-06-29 14:29:29 your server socket listen backlog is limited to 100 connections
2015-06-29 14:29:29 your mercy for graceful operations on workers is 60 seconds
2015-06-29 14:29:29 setting request body buffering size to 65536 bytes
2015-06-29 14:29:29 mapped 333952 bytes (326 KB) for 1 cores
 2015-06-29 14:29:29 *** Operational MODE: single process ***
 2015-06-29 14:29:29 WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0xc989d0 pid:       2701 (default app)
 2015-06-29 14:29:29 *** uWSGI is running in multiple interpreter mode ***
 2015-06-29 14:29:29 spawned uWSGI master process (pid: 2701)
 2015-06-29 14:29:29 spawned uWSGI worker 1 (pid: 2706, cores: 1)
 2015-06-29 14:29:29 spawned 2 offload threads for uWSGI worker 1
 2015-06-29 14:29:31 announcing my loyalty to the Emperor...

Do you think it's a threading issue? I've found that you don't allow multi-threading so I could try to work around that, if it's a worker issue I'd upgrade to a paid plan if I knew that it'd work, and in trying to rule out an environment variable issue I've tried to set as many as I know and then some in my wsgi file here:

import os
import sys
os.environ['APP_SETTINGS'] ="project.config.ProductionConfig"
os.environ['SECRET_KEY'] = 'my_precious'
os.environ['SQLALCHEMY_DATABASE_URI'] = "'sqlite:///' + join(basedir, 'wsankey$default.db')"
os.environ['DEBUG'] = 'False'
os.environ['DEBUG_TB_ENABLED'] = 'False'
os.environ['STRIPE_SECRET_KEY'] = 'foo'
os.environ['STRIPE_PUBLISHABLE_KEY'] = 'bar'
os.environ['WTF_CSRF_SECRET_KEY'] = 'this-is-not-random-but-it-should-be'
os.environ['SECURITY_PASSWORD_SALT'] = 'seasalt'
path = '/home/wsankey/ppc_flask/'
if path not in sys.path:
  sys.path.append(path)
from project import app as application
application.config.from_object(os.environ['APP_SETTINGS'])
basedir = os.path.abspath(os.path.dirname(__file__))

Any suggestions are greatly appreciated, thanks!

Have you tried running your wsgi file? That sometimes helps with debugging. Be aware that you'll have to activate your virtualenv if you're using one.

Good idea, I went to my console (with my virtual environment activated) and ran:

python /var/www/wsankey_pythonanywhere_com_wsgi.py

But it just returns me to another line of console...no error message or anything. Maybe it's not picking up the application? I'm at a loss...

That just means that it managed to import anything. If you're not seeing any other logs, your app may be stealing the logging from us so we can't output logs. Try to enable debug and see whether it's an app-level issue that can be revealed by Flask's debugging.