user10521398
user10521398

Reputation: 183

Gunicorn 'Application Object Must Be Callable' error

I'm trying to deploy an app written in Dash, using gunicorn and nginx. I successfully deployed this same app a few months ago, when I knew what I was doing. I wanted to make some updates and redeploy, but now the deployment wont work, even if I get rid of all my updates. When I run gunicorn, I get an error, Application must be callable.

I have my project in folder, which contains unified.py file, which has my app. In unified.py, app = dash.Dash(__name__, external_stylesheets=external_stylesheets) so I'm defining my app variable as app.

I run gunicorn folder.unified:app and get this error. However, if I run from folder.unified import app I get the app object and all the proper attributes, no problem.

I have tried all sorts of variations on the gunicorn call (such as being in the project folder and saying gunicornunified:app, being the parent folder and usinggunicorn folder:app,gunicorn folder:unified`. I know that it can work because it was working before. But for the life of me, I cannot figure out what is going on right now.

I expect it to run similarly to when I run the app with python using python unified.py.

There was a moment where I thought I solved it because I started getting a different error (saying I couldn't get a .pkl file from another folder), but then I commented out those lines in my unified.py file and it went back to the same Application must be callable error!

Upvotes: 10

Views: 6413

Answers (3)

Artem Fedorov
Artem Fedorov

Reputation: 97

For those who like we got exactly the same error when trying to deploy a Flask (Dash) application on AWS elastic beanstalk - you need to set the WSGIPath in Configuration/Updates, monitoring, and logging to application:server.

The filename in my case is application.py and definitions in code are:

application=dash.Dash(__name__)   
server=application.server

Upvotes: 0

nrnw
nrnw

Reputation: 531

add server after defining app in main code. (Ex:main.py)

app=dash.Dash(__name__)   
server=app.server

then run gunicorn in terminal

gunicorn main:server

if you want to access over LAN and set a port and workers

gunicorn -w 4 -b 0.0.0.0:4000 app_test:server

Upvotes: 14

user10521398
user10521398

Reputation: 183

gunicorn unified:app.server

Cross reference from the Plotly forums where I found the solution: https://community.plot.ly/t/error-with-gunicorn/8247

Upvotes: 7

Related Questions