Operation returned an invalid status 'unauthorized' when deploying Python app

Question:

I am following this guide to deploy python app on Azure. https://learn.microsoft.com/en-us/azure/devops/pipelines/ecosystems/python-webapp?view=azure-devops

I was successfully able to clone the repo and authenticated through Github in Azure Portal Shell.

But I got above error when I tried to deploy the app using the following command.
az webapp up -n PythonFlaskAppExampleApp

Asked By: Ishan Patel

||

Answers:

We need to make sure that all the configurations has been done which building python webapp.
below are few key points where we need to look into:

  1. For FlaskApp App service looks for App.py which has below content:
 If application.py
gunicorn --bind=0.0.0.0 --timeout 600 application:app
 If app.py
gunicorn --bind=0.0.0.0 --timeout 600 app:app
  1. Check for customized build automations in MS Docs

Also below are few predefined configs which needs to be set, check them one by one based on your requirement:

    az group create -n <some_name> --location westus
    az appservice plan create --name <some_name> -g <some_name> --sku s1 --location westus --is-linux
    az webapp create -g <some_name> -n <some_globaly_unique_name> --plan <some_name> --runtime "PYTHON|3.7"
    az webapp config appsettings set -g <some_name> -n <some_globaly_unique_name> --settings WEBSITE_RUN_FROM_PACKAGE="1"
    az webapp config appsettings set -g <some_name> -n <some_globaly_unique_name> --settings SCM_DO_BUILD_DURING_DEPLOYMENT=true
    az webapp restart -n <some_globaly_unique_name> -g <some_name>

    git clone https://github.com/Azure-Samples/python-docs-hello-world
    cd .python-docs-hello-world
    Compress-Archive -Path * -DestinationPath package.zip
    az webapp deployment source config-zip -n <some_globaly_unique_name> -g <some_name> --src .package.zip

Note: Check for your current versions and replace them accordingly.

Answered By: SaiKarri-MT

For some reason, I had to manually create app-service from Azure Portal UI, as az webapp up -n <your-appservice> command didn’t work. It deployed app successfully after creating it.

Answered By: Ishan Patel

Try running az account set -s <Subscription ID> first.

Answered By: Abyszero