Azure-cli: webapp:'NoneType' object has no attribute 'location' error when setting up Github deployment

Created on 9 Jun 2018  路  20Comments  路  Source: Azure/azure-cli

Describe the bug
When setting up Github deployment, the following command returns an error for one of my resource groups.

'NoneType' object has no attribute 'location'
Traceback (most recent call last):
  File "/usr/local/Cellar/azure-cli/2.0.31/libexec/lib/python3.6/site-packages/knack/cli.py", line 197, in invoke
    cmd_result = self.invocation.execute(args)
  File "/usr/local/Cellar/azure-cli/2.0.31/libexec/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 344, in execute
    cmd.exception_handler(ex)
  File "/usr/local/Cellar/azure-cli/2.0.31/libexec/lib/python3.6/site-packages/azure/cli/command_modules/appservice/commands.py", line 51, in _polish_bad_errors
    raise ex
  File "/usr/local/Cellar/azure-cli/2.0.31/libexec/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 319, in execute
    result = cmd(params)
  File "/usr/local/Cellar/azure-cli/2.0.31/libexec/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 180, in __call__
    return super(AzCliCommand, self).__call__(*args, **kwargs)
  File "/usr/local/Cellar/azure-cli/2.0.31/libexec/lib/python3.6/site-packages/knack/commands.py", line 109, in __call__
    return self.handler(*args, **kwargs)
  File "/usr/local/Cellar/azure-cli/2.0.31/libexec/lib/python3.6/site-packages/azure/cli/core/__init__.py", line 420, in default_command_handler
    result = op(**command_args)
  File "/usr/local/Cellar/azure-cli/2.0.31/libexec/lib/python3.6/site-packages/azure/cli/command_modules/appservice/custom.py", line 703, in config_source_control
    location = _get_location_from_webapp(client, resource_group_name, name)
  File "/usr/local/Cellar/azure-cli/2.0.31/libexec/lib/python3.6/site-packages/azure/cli/command_modules/appservice/custom.py", line 1005, in _get_location_from_webapp
    return webapp.location
AttributeError: 'NoneType' object has no attribute 'location'

If I create a new resource group, everything seems to work fine. It's just this one that is a problem.

To Reproduce
Execute the command to setup Github deployment from the CLI

az webapp deployment source config --name MyAppName --resource-group myResourceGroup 
--repo-url MyRepoURL

Expected behavior
The Github deployment should be enabled on the site.

Environment summary
Installed via Home Brew
CLI Version: 2.0.31
Shell Type: Bash / zsh

Additional context
The name of the resource group is MyFirstAppResourceGroup. I'm not sure if it's safe to leave my Subscription ID here in plain text, but if that's OK. I can include that as well.

Service Attention Web Apps bug

Most helpful comment

I don't want to have to provision anything using the portal. I want Infrastructure as Code. I'm new to Azure, and I'm finding much more difficult than either AWS or GCP to do everything programmatically.

All 20 comments

@burkeholland is the App you are trying to deploy belong to the ResourceGroup 'MyFirstAppResourceGroup'? Can you share the name of the App as well? thank you.

The name of the app is MyFirstApp-burke

I should note that if I delete that Resource Group and then wait long enough, I can recreate it without any problems. It looks like this is only an issue when you delete a resource group (with a service plan and webapp in it) and then immediately recreate it.

I'm seeing the same behavior with a local git repository.

az webapp deployment slot create -n dev-ppf-missioncontrol-auth-update -g dev.ppf.missioncontrol --slot auth-update --configuration-source dev-ppf-missioncontrol-auth-update
ERROR: 'NoneType' object has no attribute 'location'
Traceback (most recent call last):
File "/opt/az/lib/python3.6/site-packages/knack/cli.py", line 197, in invoke
cmd_result = self.invocation.execute(args)
File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 366, in execute
cmd.exception_handler(ex)
File "/opt/az/lib/python3.6/site-packages/azure/cli/command_modules/appservice/commands.py", line 51, in _polish_bad_errors
raise ex
File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 343, in execute
result = cmd(params)
File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 182, in __call__
return self.handler(*args, kwargs)
File "/opt/az/lib/python3.6/site-packages/azure/cli/core/__init__.py", line 436, in default_command_handler
result = op(
command_args)
File "/opt/az/lib/python3.6/site-packages/azure/cli/command_modules/appservice/custom.py", line 775, in create_webapp_slot
location = site.location
AttributeError: 'NoneType' object has no attribute 'location'

@baileymooreatx, can you please double check whether or not the site of dev-ppf-missioncontrol-auth-update exists by running az webapp show -n dev-ppf-missioncontrol-auth-update -g dev.ppf.missioncontrol?. JFYI, the latest CLI release out yesterday will emit out an explicit error saying the app doesn't exist instead of crashing.

It doesn't exist. It does now because I had to create it using the portal. I'm trying to create a new slot on an existing webapp. I have another Jenkins pipeline that does the same thing. If you create slot(s) when you provision the App Service, it works. When I attempt to add an additional slot to an existing App Service, it crashes.

I don't want to have to provision anything using the portal. I want Infrastructure as Code. I'm new to Azure, and I'm finding much more difficult than either AWS or GCP to do everything programmatically.

It works for me now. Please re-verify

Last time I had this issue, it was because I was specifying the wrong resource group.
az webapp create --resource-group $resourceGroup --plan $hostingPlan --name $applicationName --deployment-container-image-name $dockerCustomImageName

Make sure the the resource group is the one in which your service plan is created.

Happens to me as well. In my scenario, I create a webapp, delete it, and then created an identical one with a different name, and I get this error.

This is what was happening to me as well: I created a webapp, there was a problem in my docker-compose.yml, so I deleted the webapp and created it again using the exact same "az webapp create" command I used the first time, and now I get NoneType object has no attribute 'location'.

I then re-ran the "az webapp create" with --debug, and it's telling me it Cannot find ServerFarm with name xxx. I think a server farm might be an app service plan. I definitely have an app service plan with the given name.

I was able to fix it: Even though I had an App Service Plan with the name I was using, when I went in to look at that plan it was in a zombie state: The status of the plan in the portal showed "---", and it did not show the CPU/Memory charts. Also I could not delete this app service plan in the portal normally; I had to delete the service plan by going to the resource group and deleting it from there.

I deleted and re-created my app service plan, and then this started working. I had done a "az webapp delete" a bit earlier, thinking it would delete my web app and not the service plan. Something that happened somewhere made the app service plan invalid, but still sort of showing up.

I got this error message: " az webapp create: error: 'NoneType' object has no attribute 'location' "
When running:

  • az webapp create

This solved it for me:

  • az logout
  • az login
  • az appservice plan create (not sure if this was necessary...)
  • az webapp create

Probably the plan is not in the same resource group given on command line.
Adding the '-- debug' to the command line helped get the real error message
sample statement
az webapp create --name whaterver--resource-group abcrg --plan abcpln --debug

post that, i could see the plan and service in the resource group

Just in case it helps, I got this error when the appservice plan didnt exist.

Whoever reading these issues, could you please write meaningful error messages?

If there is an error don't just print it, add a reason why it choked next to it so we don't need to debug the simplest command such as az webapp create. It looks like error comes from Python code, just put

if plan is None:
    raise Exception('Plan does not exist. Create the plan first')

How difficult is this to write? Why am I continuously googling your cryptic error messages? Why is this issue closed without fixing this error?

Using the portal I'm able to create a webapp manually referencing an already created service plan in a different resource group. Using az client I'm expecting the same... but I expent a lot of time to guess how to do it. Finally I tried -p {planresourceId} instead of -p {planresourcename} when creating web app and worked. I think this should be fixed to avoid people wasting time guessing things. Documentation says that you can use name or id in plan parameter... name seems that only works if webapp belongs to same resource group than plan.

I'm expending more time dealing with this kind of errors than writing my scripts wich is frustrating. I would expect a fix, a proper response message or a clear explanation of this "limitations" in az docs, but seems easier to close the issue.

Using the portal I'm able to create a webapp manually referencing an already created service plan in a different resource group. Using az client I'm expecting the same... but I expent a lot of time to guess how to do it. Finally I tried -p {planresourceId} instead of -p {planresourcename} when creating web app and worked. I think this should be fixed to avoid people wasting time guessing things. Documentation says that you can use name or id in plan parameter... name seems that only works if webapp belongs to same resource group than plan.

I'm expending more time dealing with this kind of errors than writing my scripts wich is frustrating. I would expect a fix, a proper response message or a clear explanation of this "limitations" in az docs, but seems easier to close the issue.

hi @ccanizares, I faced the same issue. Can you put an example of your command line for this?

Thanks.

Using the portal I'm able to create a webapp manually referencing an already created service plan in a different resource group. Using az client I'm expecting the same... but I expent a lot of time to guess how to do it. Finally I tried -p {planresourceId} instead of -p {planresourcename} when creating web app and worked. I think this should be fixed to avoid people wasting time guessing things. Documentation says that you can use name or id in plan parameter... name seems that only works if webapp belongs to same resource group than plan.
I'm expending more time dealing with this kind of errors than writing my scripts wich is frustrating. I would expect a fix, a proper response message or a clear explanation of this "limitations" in az docs, but seems easier to close the issue.

hi @ccanizares, I faced the same issue. Can you put an example of your command line for this?

Thanks.

Great Thanks , I Put the ID and It actually did the magic

I got this error message: " az webapp create: error: 'NoneType' object has no attribute 'location' "
When running:

  • az webapp create

This solved it for me:

  • az logout
  • az login
  • az appservice plan create (not sure if this was necessary...)
  • az webapp create

This approach is work for me .... thank you ..

Using the portal I'm able to create a webapp manually referencing an already created service plan in a different resource group. Using az client I'm expecting the same... but I expent a lot of time to guess how to do it. Finally I tried -p {planresourceId} instead of -p {planresourcename} when creating web app and worked. I think this should be fixed to avoid people wasting time guessing things. Documentation says that you can use name or id in plan parameter... name seems that only works if webapp belongs to same resource group than plan.
I'm expending more time dealing with this kind of errors than writing my scripts wich is frustrating. I would expect a fix, a proper response message or a clear explanation of this "limitations" in az docs, but seems easier to close the issue.

hi @ccanizares, I faced the same issue. Can you put an example of your command line for this?

Thanks.

Since no one did answer so far, this is the approach that i used in the end:
First, get the id of the app service

// If you know the resource group
planId=$(az appservice plan show --name MYPLAN --resource-group MYOTHERGROUP --query "id" -o tsv)

// If you don't know the resource group
planId=$(az appservice plan list --query "[?name=='MYPLAN'].id" -o tsv | head -n 1)

Then, create the WebAppp with that ID as parameter:

az webapp create --name MYAPP --resource-group MYGROUP --plan $planId

And, if you're using Git Bash, like me, since the resource id has a syntax like this /subscriptions/x/resourceGroups/y/providers/Microsoft.Web/serverfarms/z, the parameter will always be prefixed with the filepath to your git bash or something like that, so it will become 'C:/Program Files/Git/subscriptions/x/resourceGroups/y/providers/Microsoft.Web/serverfarms/z or something similar.

To avoid that, you have to set env var MSYS_NO_PATHCONV before running the command, like this:

MSYS_NO_PATHCONV=1 az webapp create --name MYAPP --resource-group MYGROUP --plan $planId

see also here on more info how to use Git Bash with azure cli.

This doesn't seem to be fixed. If plan id is required not plan name, it seems like a new parameter should be required otherwise, this is not consistent with other Azure CLI usage of --name

Was this page helpful?
0 / 5 - 0 ratings