0

I have been trying to call the quota.get() method and it works for all resource names that doesn't have a space or underscore in the name, for example: "standardNCFamily" works but not for the rest like, "Standard NCASv3_T4 Family" does not.

# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------

from azure.identity import DefaultAzureCredential
from azure.mgmt.quota import AzureQuotaExtensionAPI

"""
# PREREQUISITES
    pip install azure-identity
    pip install azure-mgmt-quota
# USAGE
    python quotas_list_quota_limits_for_compute.py
    Before run the sample, please set the values of the client ID, tenant ID and client secret
    of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
    AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
    https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""


def main():
    client = AzureQuotaExtensionAPI(
        credential=DefaultAzureCredential(),
    )

    response = client.quota.list(
        scope="subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Compute/locations/eastus",
    )
    for item in response:
        print(item)


# x-ms-original-file: specification/quota/resource-manager/Microsoft.Quota/preview/2021-03-15-preview/examples/getComputeQuotaLimits.json
if __name__ == "__main__":
    main()

This is the sample code from samples repo in the Azure python github here

And this is the error I get when I call for the NCAS_v3 type of instances:

Traceback (most recent call last):
  File "/Users/name/PycharmProjects/Virga-API/azure/trytry.py", line 35, in <module>
    main()
  File "/Users/name/PycharmProjects/Virga-API/azure/trytry.py", line 25, in main
    response = client.quota.get(
  File "/Users/name/PycharmProjects/Virga-API/venv/lib/python3.10/site-packages/azure/core/tracing/decorator.py", line 78, in wrapper_use_tracer
    return func(*args, **kwargs)
  File "/Users/name/PycharmProjects/Virga-API/venv/lib/python3.10/site-packages/azure/mgmt/quota/operations/_quota_operations.py", line 237, in get
    raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat)
azure.core.exceptions.HttpResponseError: (InvalidResourceName) Name %60%60Standard%20NCASv3_T4%20Family%60%60 is not valid resource name.
Code: InvalidResourceName
Message: Name %60%60Standard%20NCASv3_T4%20Family%60%60 is not valid resource name.

I've been at it for hours trying different configurations for the names but can't seem to find it. The documentation doesn't mention anything either.

Any help would be awesome!

guidingfox
  • 77
  • 2
  • 12

1 Answers1

0

It seems that your name contains underscores and spaces and you're accessing it in the wrong way without any casting and space safety resource, make sure that your resource name should match the name of the resource you want to retrieve information about, and it should be formatted correctly. For example, to retrieve information about Standard NCASv3_T4 Family instances, you should pass "Standard NCASv3_T4 Family" as your resource name to the quota.get() method, so your code should be like quota.get("Standard NCASv3_T4 Family") it should work anyway, if not, make sure you imported the correct resource type when calling the quota.get() method. The resource type you're using should match the type of that resource that you're trying to retrieve information about. For example, if you're trying to retrieve information about Standard NCASv3_T4 Family instances, you should use the resource type "virtualMachineScaleSets" resource type, and also don't forget to check standard documentation they're always a good resource for everything!!

  • Thank you for the answer! But I tried to call it like this: `quota.get("Standard NCASv3_T4 Family")` but it isn't working. Could you explain a bit more about how to escape the characters? I tried everything I know, but nothing works. Could you maybe help me with this particular one: `Standard NCASv3_T4 Family` ? I've been following this doc: https://learn.microsoft.com/en-us/samples/azure-samples/azure-samples-python-management/quota/ – guidingfox Dec 28 '22 at 07:28
  • Check the resource that you used it maybe cause the problem. – Ehsan Faramarz Dec 30 '22 at 14:18