Deploying Python web application to Azure

Jeff Williams 1 Reputation point
2022-04-17T19:46:27.273+00:00

Hello, I am trying to deploy a simple web application to Azure. I have followed two tutorials (https://learn.microsoft.com/en-us/azure/app-service/quickstart-python?tabs=flask%2Cwindows%2Cazure-portal%2Cvscode-deploy%2Cterminal-bash%2Cdeploy-instructions-azportal%2Cdeploy-instructions-zip-azcli) and (https://medium.com/@GeekTrainer/deploying-python-web-apps-to-azure-app-services-413cc16d4d68) as well as a few youtube videos. I'm using a simple hello world python app (app.py and requirements.txt) with pycharm and Github. My app continues to fail to deploy (after about 8 hrs of trying) and says "Your web app is running and waiting for your content". Is there a better tutorial or method to try? Getting pretty beat up by this...and would appreciate any help.

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
{count} votes

2 answers

Sort by: Most helpful
  1. ajkuma 28,111 Reputation points Microsoft Employee Moderator
    2022-04-20T11:17:54.617+00:00

    @Jeff Williams ,

    Just following-up from TakahitoIwasa's post - checking in to see if the issue is resolved or you need further assistance.

    I understand that you have already tried the suggestions outlined in the Azure docs and watched a few demo videos.
    Apologies for any frustration with this.

    -- For Flask, App Service looks for a file named application.py or app.py (as in your case) and starts Gunicorn as follows:

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

    If you haven’t done these already, please validate these:

    1. Use SSH to connect directly to the App Service container and verify that your files exist under site/wwwroot. If your files don't exist, use the following steps:
      -Create an app setting named SCM_DO_BUILD_DURING_DEPLOYMENT with the value of 1, redeploy your code, wait a few minutes, then try to access the app again. -- For more information on creating app settings, see Configure an App Service app in the Azure portal.
    2. Review your deployment process, check the deployment logs, correct any errors, and redeploy the app.
      --Examine the app log stream for any error messages. The logs will show any errors in the app code.
    3. If your files exist, then App Service wasn't able to identify your specific startup file. Review that your app is structured as App Service expects for your Flask app, or use a custom startup command.
      https://learn.microsoft.com/azure/app-service/configure-language-python#customize-startup-command
    4. Be sure you're using App Service for Linux rather than a Windows-based instance. --From the Azure CLI, run the command az webapp show --resource-group <resource-group-name> --name <app-name> --query kind, replacing <resource-group-name> and <app-name> accordingly.

    You should see app,linux as output; otherwise, recreate the App Service and choose Linux.
    https://learn.microsoft.com/azure/app-service/configure-language-python#flask-app

    Kindly let us know how it goes, we will be more than happy to follow-up further.

    1 person found this answer helpful.
    0 comments No comments

  2. Jeff Williams 1 Reputation point
    2022-04-20T14:52:41.617+00:00

    @Takahito Iwasa @Anonymous Thank you for your quick replies. For the quick start method I was able to run the quick start app locally using pycharm (I don't have flask or django on my local machine). I also pushed the quick start package to my github repo (not a local git).

    For Step 2: I used the CLI but (az webapp up) threw an error (unable to find location and resource group). This method was also mentioned in a youtube video.
    Then I tried the Azure portal method which worked find (other than having trouble finding a location to use westcentralus seemed to work)

    For step 3: I dont have a local git or VS code...so I used the cli to deploy using this code from the second link as webapp up doesnt work for me. The deployments succeeded but visiting the web page after days says the app is waiting on my code

    I did not have the server exposed using the gunicorn command above (I remember doing this for plotly). Is there an easy way to find the various error logs?

    I will try the steps you mentioned above and report back. Thank you


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.