Search code examples
azureazure-active-directoryazure-sdk-python

Unable to list locks using list_at_resource_level in azure


compute_client = authenticate.client_management(subscription_id)
for resource_group in resources_groups.keys():
    vm_list = compute_client.virtual_machines.list(resource_group)
for vm in vm_list:
    array = vm.id.split("/")
    locks_client = authenticate.locks_client(subscription_id)
    result = locks_client.management_locks.list_at_resource_level(resource_group, "Microsoft.Compute",
                                                                  "/subscriptions/XXXXXX/resourceGroups/YYYY",
                                                                  "Microsoft.Compute/virtualMachines", array[-1])

Using the following class for locks ::

/usr/local/lib/python3.8/dist-packages/azure/mgmt/resource/locks/v2016_09_01/operations/_management_locks_operations.py

The result of the above program is ::

azure.core.exceptions.ResourceNotFoundError: (InvalidResourceType) The resource type could not be found in the namespace 'Microsoft.Compute' for api version '2016-09-01'.
Code: InvalidResourceType

Can someone please help me fix this.

Thanks.


Solution

  • azure.core.exceptions.ResourceNotFoundError:(InvalidResourceType) The resource type could not be found in the namespace 'Microsoft.Compute' for api version '2016-09-01'. Code: InvalidResourceType

    The above error is usually occurs:

    • API version not supported for the resource type.
    • Location not supported for the resource type.
    • The required resource provider hasn't been registered for your subscription.

    The above used Api version is not supported in resourcetypes kindly check the below image has been provided listed of api version in it.

    Check and use the correct API Versions:

    enter image description here

    Locations:

    enter image description here

    Reference: View resource provider-MSFT Docs