Forums

Dash app throws Attribute Error: 'Flask' object has no attribute 'server'

I have a Dash app that runs fine locally. It also renders as a pythonanywhere website but it has none of the functionality that it should. It appears to be only static and the browser tabs title shows "Updating".

When I check the error logs I find:

Error running WSGI application AttributeError: 'Flask' object has no attribute 'server' File "/var/www/mpetta_pythonanywhere_com_wsgi.py", line 18, in <module> application = app.server

I have tried renaming the file and aliasing the import but nothing seems to resolve this error. Any help would be greatly appreciated. Thank you

How are you initializing "app"?

I have this line in textgen_app.py :

app = Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])

And this is the wsgi.py :

import sys
project_home = '/home/mpetta/textgen'
if project_home not in sys.path:
    sys.path = [project_home] + sys.path

from textgen_app import app
application = app.server

Make sure you're serving the right web app code -- what kind of messages do you see in the error log?

it seems all the paths and directories are pointing to where I want them to.

When I launch the app I get this in the error log:

Error running WSGI application AttributeError: 'Flask' object has no attribute 'server' File "/var/www/mpetta_pythonanywhere_com_wsgi.py", line 18, in <module> application = app.server

Oddly enough the app is then available at mpetta.pythonanywhere.com but it doesn't allow for the input and output callbacks that Dash should allow. It only displays the page elements. When I attempt to use a callback such as submitting user input the error log shows:

OSError: write error

We have a help page on how to configure Dash on PythonAnywhere

I followed the information provided on that page. Per that recommendation, this is exactly what I have in the wsgi.py file:

import sys
project_home = '/home/mpetta/textgen'
if project_home not in sys.path:
    sys.path = [project_home] + sys.path

from textgen_app import app
application = app.server

Even following that pages guide the deployment throws the error:

"Error running WSGI application AttributeError: 'Flask' object has no attribute 'server' File "/var/www/mpetta_pythonanywhere_com_wsgi.py", line 18, in <module> application = app.server"

Why is the error log showing this "WSGI application AttributeError" but the page elements for the app all display at the URL. If the WSGI.py is failing then there should be nothing showing on the URL. is that assumption correct?

Flask? are you importing flask in your web app code?

I am using the Dash module which is "built on top of Flask" per the documentation. https://dash.plotly.com

Ah okay so that why it's complaining about the Flask object not having a server attribute. The problem then may be in initializing the server