How to deploy Python Flask app on Linux enviroment of Azure App Services using Azure Portal?

Alban Vicarini 1 Reputation point
2022-04-06T12:07:52.347+00:00

Hello All,

Actually I have tried to deploy my Python Flask app on Linux Azure App Service but after deployment I am not able to access my app application.

Steps:

1) I create Linux base Azure App Service on Azure using Azure Portal in which I select python 3.8.
2) I select free basic version for starting and create service.
3) After successfully creation of Azure App Service I go back to my VS code and in VS code I am able to see this new app service.
4) I right click on the newly create app service and click on deploy
5) After deployment when I tried to access my url I got an error even I am not able to see my deployed code when i use KUDU from Azure App Service.

I have checked many urls and follow same steps but still not successfully deploy my Python Flask app on Linux base Azure App Service.

Can any one help me on this please?

Thank you in advance

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

3 answers

Sort by: Most helpful
  1. Takahito Iwasa 4,641 Reputation points MVP
    2022-04-06T21:29:34.297+00:00

    Hi, @Alban Vicarini

    1. Can you share run-time errors?
    2. Try deploying the Python Flask app according to the following URL (https://learn.microsoft.com/en-us/azure/developer/python/tutorial-deploy-app-service-on-linux-02?tabs=cmd)

  2. SnehaAgrawal-MSFT 12,626 Reputation points Microsoft Employee
    2022-04-07T17:27:24.263+00:00

    Thanks for asking question!

    In general, The first step in troubleshooting is to use App Service Diagnostics:

    1. On the Azure portal for your web app, select Diagnose and solve problems from the left menu.
    2. Select Availability and performance.
    3. Examine the information in the Application Logs, Container crash, and Container Issues options, where the most common issues will appear.
    4. Check if your container was able to complete startup.
    5. If the container couldn't start or exited, look at the AppLogs to see if the application error is causing the webserver/application to fail to respond successfully to the Platform's HTTP Ping or if there is an unhandled exception causing the container crash during runtime. Note: Looking internally it seems your HTTP Logging is currently set to false. This means that you will not see any logs from your app itself unless
      your app was failing to start. Its recommended to turn on HTTP Logging to be able to see application logs to help diagnose and solve
      potential issues.
    6. Next, examine both the deployment logs and the app logs for any error messages. These logs often identify specific issues that can prevent app deployment or app startup.
      Crashes at startup will be logged with the text: "Container 'container name' couldn't be started"
      Crashes at runtime will be logged with the text: "Container exited unexpectedly"
      Check for the 5 latest application logs
    7. Assess and fix/handle the exceptions that maybe causing the container to crash/exit at startup or during runtime.

    In your case it seems there are Application Errors that may have caused the container to crash were detected

    Error1:

    Could not find virtual environment directory /home/site/wwwroot/antenv.2022-04-07T06:03:22.842783748Z WARNING: Could not find package directory /home/site/wwwroot/__oryx_packages__.

    Recommended Action: The application maybe facing a generic error which is causing your app to fail proper startup. To access your logs go to https://tennisliveapp.scm.azurewebsites.net/api/logs/docker and review them by opening the files with the words default_docker.log

    Error2: ModuleNotFoundError: No module named 'flask_restful' error

    Cause: The application maybe missing a Python package which is causing your app to fail proper startup.

    Recommended Action: If you see an error like ModuleNotFoundError: No module named 'example', this means that Python could not find one or more of your modules when the application started. This most often occurs if you deploy your virtual environment with your code. Virtual environments are not portable, so a virtual environment should not be deployed with your application code. Instead, let Oryx create a virtual environment and install your packages on the web app by creating an app setting, SCM_DO_BUILD_DURING_DEPLOYMENT, and setting it to 1.

    This will force Oryx to install your packages whenever you deploy to App Service. For more information, please see this article on virtual environment portability.

    Further Refer this article to deploy your app properly.

    Also, you may requires more than 230 seconds to complete initialization and respond successfully to the Platform's HTTP Ping , we allow you to increase that 230 second wait time up to a limit of 1800 seconds. To configure that, add an app setting called WEBSITES_CONTAINER_START_TIME_LIMIT and set it to the number of seconds you would like for us to wait for your container to start.

    Check this link: https://learn.microsoft.com/en-us/archive/blogs/waws/things-you-should-know-web-apps-and-linux#if-your-container-takes-a-long-time-to-start-increase-the-start-time-limit

    Let us know if further query or issue remains.

    0 comments No comments

  3. ncorr 1 Reputation point
    2022-05-30T09:37:02.557+00:00

    If you found a solution share it please, i got the same issue with the deployment. I have already tried to change the Start time limit and put to 1 SCM_DO_BUILD_DURING_DEPLOYMENT. And i still have the same issue.

    0 comments No comments