How can I fix this application error on python dash app to azure web app services

Amanda Danielle Gomez 5 Reputation points
2023-09-12T15:21:23.9466667+00:00

hello. I am having troubling deploying my Python Dash App. I see that is was deployed successfully from github to the azure portal but the problem is that every time I try to load the site, I get application error. this is the error/s im getting in my log screen.

Screenshot 2023-09-12 at 11.17.57 AM (2)

This is my code

from my code

import dash
from dash import dcc, html
from dash.dependencies import Input, Output
import plotly.express as px
import pandas as pd
import pyodbc
import dash_bootstrap_components as dbc
from credentials import DB_USERNAME, DB_PA #database credentials

# Initialize the Dash app with a Bootstrap theme
app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])

......more code

# Establish the connection to the database
    server = "carserver1.database.windows.net"
    database = "cardb"
    driver = "{ODBC Driver 18 for SQL Server}"
    
    conn_str = f"DRIVER={driver};SERVER={server};DATABASE={database};UID={DB_USERNAME};PWD={DB_PASSWORD}"
    connection = pyodbc.connect(conn_str)
    
    # Query data for the selected brand from the database
    query = f"SELECT * FROM CARSINFO WHERE Brand = '{selected_brand}'"
    filtered_df = pd.read_sql(query, connection)
    
    connection.close()

...more code charts etc... then

# Run the app
if __name__ == '__main__':
    app.run_server(debug=True)


this is my requirements.txt

dash==2.12.1
dash-bootstrap-components==1.5.0
gunicorn
plotly==5.16.1
pandas==2.0.3
pyodbc==4.0.39

this is my start command under the configurations on the azure portal

gunicorn --bind=0.0.0.0 --timeout 600 app:server

this is the log stream

2023-09-12T15:00:31.674Z INFO  - 3.11_20230810.1.tuxprod Pulling from appsvc/python
2023-09-12T15:00:31.694Z INFO  -  Digest: sha256:b20f97f273c1e7f04b68ed29ddbffca33e0993ff4ef07b02f80a211fef22c955
2023-09-12T15:00:31.696Z INFO  -  Status: Image is up to date for mcr.microsoft.com/appsvc/python:3.11_20230810.1.tuxprod
2023-09-12T15:00:31.716Z INFO  - Pull Image successful, Time taken: 0 Minutes and 0 Seconds
2023-09-12T15:00:32.548Z INFO  - Starting container for site
2023-09-12T15:00:32.550Z INFO  - docker run -d --expose=8000 --name vmdanalysisdashboard_0_7911c70f -e WEBSITE_SITE_NAME=VMDAnalysisDashboard -e WEBSITE_AUTH_ENABLED=False -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=vmdanalysisdashboard.azurewebsites.net -e WEBSITE_INSTANCE_ID=59fae4ded1336232cdf24f5fd85008c3bb1c6258f576cf4e74e210e8cb875811 -e HTTP_LOGGING_ENABLED=1 -e WEBSITE_USE_DIAGNOSTIC_SERVER=False appsvc/python:3.11_20230810.1.tuxprod gunicorn --bind=0.0.0.0 --timeout 600 app:server
2023-09-12T15:00:33.392Z INFO  - Initiating warmup request to container vmdanalysisdashboard_0_7911c70f for site vmdanalysisdashboard
2023-09-12T15:00:33.087119948Z    _____
2023-09-12T15:00:33.087178848Z   /  _  \ __________ _________   ____
2023-09-12T15:00:33.087205248Z  /  /_\  \\___   /  |  \_  __ \_/ __ \
2023-09-12T15:00:33.087209148Z /    |    \/    /|  |  /|  | \/\  ___/
2023-09-12T15:00:33.087212648Z \____|__  /_____ \____/ |__|    \___  >
2023-09-12T15:00:33.087216248Z         \/      \/                  \/
2023-09-12T15:00:33.087219648Z A P P   S E R V I C E   O N   L I N U X
2023-09-12T15:00:33.087223048Z
2023-09-12T15:00:33.087226348Z Documentation: http://aka.ms/webapp-linux
2023-09-12T15:00:33.087229548Z Python 3.11.4
2023-09-12T15:00:33.087232848Z Note: Any data outside '/home' is not persisted
2023-09-12T15:00:34.687379279Z Starting OpenBSD Secure Shell server: sshd.
2023-09-12T15:00:34.745767959Z Site's appCommandLine: gunicorn --bind=0.0.0.0 --timeout 600 app:server
2023-09-12T15:00:34.862279119Z Starting periodic command scheduler: cron.
2023-09-12T15:00:34.867644135Z Launching oryx with: create-script -appPath /home/site/wwwroot -output /opt/startup/startup.sh -virtualEnvName antenv -defaultApp /opt/defaultsite -userStartupCommand 'gunicorn --bind=0.0.0.0 --timeout 600 app:server'
2023-09-12T15:00:34.891426609Z Found build manifest file at '/home/site/wwwroot/oryx-manifest.toml'. Deserializing it...
2023-09-12T15:00:34.892870913Z Build Operation ID: 06040187860293db
2023-09-12T15:00:34.897215526Z Oryx Version: 0.2.20230707.1, Commit: 0bd28e69919b5e8beba451e8677e3345f0be8361, ReleaseTagName: 20230707.1
2023-09-12T15:00:34.898021029Z Output is compressed. Extracting it...
2023-09-12T15:00:34.899025532Z Extracting '/home/site/wwwroot/output.tar.gz' to directory '/tmp/8dbb399d4af9a74'...
2023-09-12T15:00:48.745345980Z App path is set to '/tmp/8dbb399d4af9a74'
2023-09-12T15:00:48.802981619Z Writing output script to '/opt/startup/startup.sh'
2023-09-12T15:00:48.879380235Z Using packages from virtual environment antenv located at /tmp/8dbb399d4af9a74/antenv.
2023-09-12T15:00:48.879432835Z Updated PYTHONPATH to '/opt/startup/app_logs:/tmp/8dbb399d4af9a74/antenv/lib/python3.11/site-packages'
2023-09-12T15:00:49.813823512Z [2023-09-12 15:00:49 +0000] [74] [INFO] Starting gunicorn 21.2.0
2023-09-12T15:00:49.820182138Z [2023-09-12 15:00:49 +0000] [74] [INFO] Listening at: http://0.0.0.0:8000 (74)
2023-09-12T15:00:49.820281439Z [2023-09-12 15:00:49 +0000] [74] [INFO] Using worker: sync
2023-09-12T15:00:49.824813858Z [2023-09-12 15:00:49 +0000] [75] [INFO] Booting worker with pid: 75
2023-09-12T15:01:01.455238812Z Failed to find attribute 'server' in 'app'.
2023-09-12T15:01:01.456215316Z [2023-09-12 15:01:01 +0000] [75] [INFO] Worker exiting (pid: 75)
2023-09-12T15:01:02.169007063Z [2023-09-12 15:01:02 +0000] [74] [ERROR]Worker (pid:75) exited with code 4
2023-09-12T15:01:02.169969166Z [2023-09-12 15:01:02 +0000] [74] [ERROR] Shutting down: Master
2023-09-12T15:01:02.172962976Z [2023-09-12 15:01:02 +0000] [74] [ERROR] Reason: App failed to load.
2023-09-12T15:01:04.072Z ERROR - Container vmdanalysisdashboard_0_7911c70f for site vmdanalysisdashboard has exited, failing site start
2023-09-12T15:01:04.084Z ERROR - Container vmdanalysisdashboard_0_7911c70f didn't respond to HTTP pings on port: 8000, failing site start. See container logs for debugging.
2023-09-12T15:01:04.088Z INFO  - Stopping site vmdanalysisdashboard because it failed during startup.
2023-09-12T15:02:13  No new trace in the past 1 min(s).

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
5,662 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Amanda Danielle Gomez 5 Reputation points
    2023-09-12T17:34:11.4466667+00:00

    hello, I just want to say I solved this on my own. the problem is in this section of my code. Although it runs fine locally, in order for it to be ran correctly in the azure environment I added the following

    # Original code to Initialize the Dash app with a Bootstrap theme 
    
    app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])
    
    # UPDATED CODE to Initialize the Dash app with a Bootstrap theme 
    
    app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])
    server = app.server
    
    1 person found this answer helpful.
    0 comments No comments

  2. SnehaAgrawal-MSFT 15,036 Reputation points Microsoft Employee
    2023-09-21T14:39:13.0133333+00:00

    Thanks for sharing the resolution that helps you.

    0 comments No comments