Forums

Deploying a Dash App Gives: AttributeError: 'Flask' object has no attribute 'server'

Hello,

I am trying to deploy a Dash application (built on top of Flask) at the url: https://jonathanbechtel.pythonanywhere.com

I read the post here: https://help.pythonanywhere.com/pages/DashWSGIConfig/ and change my wsgi configuration file so it reads in the following way:

import sys

# add your project directory to the sys.path
project_home = '/home/jonathanbechtel/covid-app/src'
if project_home not in sys.path:
    sys.path = [project_home] + sys.path

# import flask app but need to call it "application" for WSGI to work
from app import app  # noqa
application = app.server

My main file is called app.py

When I do this the application does not load and the error message is the following:

Error running WSGI application
2021-01-19 04:26:35,013: AttributeError: 'Flask' object has no attribute 'server'
2021-01-19 04:26:35,013:   File "/var/www/jonathanbechtel_pythonanywhere_com_wsgi.py", line 17, in <module>
2021-01-19 04:26:35,014:     application = app.server

If I change the import line in wsgi.py to

from app import app as application

Then the site just spits out a generic 'hello from flask!` welcome page.

Any help would be appreciated. Thank you.

It looks like you had app defined as a Flask instance, not Dash, but it seems to be fixed now?

Yes, it's since been fixed. I think the issue is that I did something to override the main app file, because when I went to open it up it was a basic Hello World flask app, not the one that I originally uploaded. Once I got back to the original version everything worked as expected. Thank you!

Glad to see that you were able to fix it!

Hi, trying to run my dash app and i keep getting the error
application.run_server(debug=False) AttributeError: 'Flask' object has no attribute 'run_server' Any help would be appreciated thank you

How do you run it? You need to configure and run it as a web app. See https://help.pythonanywhere.com/pages/DashWSGIConfig/