python code deployment to Azure windows web app through Deployment Center connecting Azure Repos

SivaB 96 Reputation points
2023-06-03T07:33:46.3833333+00:00

Requirement:

I wanted to deploy Python code using fastapi to Azure windows web App through Deployment center connecting azure repos git. The python code has main.py and requirements.txt files, we could able to get the output in local host.

Solution I tried:
I followed the doc "Quickstart: Deploy a Python (Django or Flask) web app to Azure App Service" to deploy my code to windows web app but I'm not seeing any output on the web app it's saying the default page.

"The website is running Python 3.6.6 There is nothing here yet, but Microsoft Azure makes it simple to publish the content with Git, FTP or your favorite development tool such as VS, VS Online or WebMatrix"

I'm using Visual Studio code as local workstation, do I need to Build & Publish the Python code before deploying to Azure service.

Please help me on this.

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

Accepted answer
  1. VasimTamboli 5,215 Reputation points
    2023-06-04T12:01:51.0166667+00:00

    follow these steps:

    Create an Azure App Service (Windows) in the Azure portal.

    • Go to the Azure portal (portal.azure.com) and navigate to your resource group.
    • Click on "Add" to create a new resource.
    • Search for "Web App" and select "Web App" from the results.
    • Fill in the required details like App name, subscription, resource group, and runtime stack (Python).
    • Choose the appropriate region and pricing tier.
    • Click on "Review + Create" and then "Create" to create the Azure App Service.

    Set up Azure Repos for your code.

    • In the Azure portal, navigate to your Azure App Service.
    • In the left-hand menu, under "Deployment", click on "Deployment Center".
    • Select "Azure Repos" as the source control option.
    • Follow the prompts to connect to your Azure Repos repository and choose the branch to deploy.

    Configure deployment settings.

    • In the Deployment Center, choose the appropriate build provider (e.g., Azure Pipelines or Kudu) and configure the necessary settings.
    • Make sure the build pipeline is set up to build your Python code and create the necessary artifacts (e.g., a ZIP file containing your code).
    • Configure the deployment options, such as selecting the target folder for deployment and enabling deployment slots if needed.
    • Review and save the deployment settings.

    Build and publish the Python code.

    • In your local development environment (e.g., Visual Studio Code), make sure you have the necessary dependencies and packages installed.
    • Use a tool like pip to install the required packages listed in your requirements.txt file.
    • Build and test your Python code locally to ensure it's running correctly.
    • Commit and push your code changes to your Azure Repos repository.

    Trigger the deployment.

    • In the Azure portal, go to your Azure App Service and navigate to the Deployment Center.
    • Select the appropriate branch and click on the "Sync" button to trigger the deployment process.
    • The deployment process will build and deploy your Python code to the Azure App Service.
    • Monitor the deployment process for any errors or warnings.

    Once the deployment is completed, you should be able to access your FastAPI application on the Azure Windows Web App using the provided URL. Make sure the necessary routes and endpoints are correctly configured in your FastAPI applicatio

    Regarding the issue you mentioned about not seeing any output on the Web App and seeing the default page message, here are a few things to check:

    • Ensure that your FastAPI application is correctly configured in the main.py file.
    • Check the logs in the Azure portal for any error messages or issues during the deployment process.
    • Verify that the required dependencies listed in the requirements.txt file are properly installed during the build process.
    • Double-check the routing and URLs in your FastAPI application to ensure they match the Azure Web App's URL.

1 additional answer

Sort by: Most helpful
  1. VenkateshDodda-MSFT 24,951 Reputation points Microsoft Employee Moderator
    2023-06-05T06:22:45.2333333+00:00

    @SivaB Thank you for reaching out to Microsoft Q&A , apologize for any inconvenience caused on this.

    Adding to Vasim Tamboli Answer. Based on the shared information, I have understood that you are using python3.6 and trying to deploy your FastAPI to Azure webapp which is running on Windows App service plan,

    • As mentioned here in this GitHub article, Unfortunately Python 3.6 is already reached End of life support on azure app service existing app service will continue to run and if you want to deploy your FastApi with that specific runtime version would recommend using Windows containers or use the latest runtime version of python 3.11 which is supported on Linux platform only.
    • And also, it is always recommended to use the latest runtime versions in your applications.
    • If you are seeing the default page even after your code got deployed successfully try to connect to app service kudu using ssh and under site/wwwroot make sure that the deployed files were present on not.
    • If your files exist, then App Service wasn't able to identify your specific startup file. Check that your app is structured as App Service expects for Django or Flask, or use a custom startup command.

    You can refer to this documentation for Troubleshooting Python apps on app service.

    Feel free to reach back to me if you have any further questions on this,

    0 comments No comments

Your answer

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