Forums

Deploy Dash app >> AttributeError: 'Flask' object has no attribute 'server'

Hi, I get this error while trying to deploy the app on pit66.eu.pythonanywhere.com:

2023-03-07 09:47:53,808: ***************************************************
2023-03-07 09:47:55,485: Error running WSGI application
2023-03-07 09:47:55,485: AttributeError: 'Flask' object has no attribute 'server'
2023-03-07 09:47:55,486:   File "/var/www/pit66_eu_pythonanywhere_com_wsgi.py", line 18, in <module>
2023-03-07 09:47:55,486:     application = app.server
2023-03-07 09:47:55,486: ***************************************************

My app is called app8.py and I have changed the wsgi-file:

import sys
project_home = '/home/pit66/dash'
if project_home not in sys.path:
   sys.path = [project_home] + sys.path
from app8 import app
application = app.server

From the tutorials I have seen this should do the job. I even set up a virtual environment on PA, but to no avail. Maybe I do not see the forest for the trees. Any help would be appreciated. Thanks!

[edit by admin: formatting]

It sounds like the variable app in your file app8.py is a Flask app rather than a Dash app. What code do you have in that file?

No, it is a Dash app, Giles. I just tried it locally, everything works! See beginning of code...


import json
from dash import Dash, dcc, html
from dash.dependencies import Input, Output
import plotly.express as px
import pandas as pd

external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']

app = Dash(__name__, external_stylesheets=external_stylesheets)

Which file is the code in your last message in?

It is the start of my Dash application: app8.py

Can we take a look at your files? We can see them from our admin interface, but we always ask for permission first.

Sure, no problem. It is a code example from the official Dash site...

I've just looked at /home/pit66/dash/app8.py and it looks like a default Flask app file created by our web app wizzard (returning 'Hello from Flask!'). Could you double check that you put your code it the place that you're expecting it to be?

Ok, finally I got things working :-) Two things to mention: 1. I found in the app8.py file (which I uploaded) the original code of the wizzard's flask app. No clue, how this could happen... 2. My dash app would not run without the venv I provided. Without it I get an import error:


2023-03-09 13:31:07,128: Error running WSGI application 2023-03-09 13:31:07,129: ImportError: cannot import name 'Dash' from 'dash' (unknown location) 2023-03-09 13:31:07,129: File "/var/www/pit66_eu_pythonanywhere_com_wsgi.py", line 17, in <module> 2023-03-09 13:31:07,130: from app8 import app


But I see that dash is included which are provided by PA as a standard. Is there a was to deploy without the venv?

Thanks for the support! Peter

Check here and make sure that the Python version that you are using has dash installed for the system image you're using. If it does not, use a Python version for your web app that does have it included, then you will not need the virtualenv.