Black Lives Matter. Please consider donating to Black Girls Code today.

Error with Gunicorn -- "Application object must be callable."

Hello,

I continue to receive the following error message when I try to test Gunicorn:

“Application object must be callable.”

The command I run, which errors out, is: “gunicorn app:app.server -b 0.0.0.0:8050”.

When I run “sudo python3 app.py” I don’t receive any issues and the app is presented at http://:8050. Why would gunicorn not bind properly in this case?

Any assistance would be greatly appreciated!

The documentation is a little cryptic, but from your syntax I assume you’re trying to reference the server attribute of your app instance. What you need to do instead is create a global variable server = app.server and invoke it with something like gunicorn app:server --bind=127.0.0.1:8050.

There might be some additional issues with your python environment if you’re having to use sudo python3 app.py to launch your app (gunicorn may or may not be installed in the root user’s python interpreter, which is what you’re using to run your app when you invoke python3 with sudo privileges), so if you get any weird error messages about dependencies not being installed you might try following these instructions.