[Python] AzureDefaultCredentials fail with Authorization Code: None

Discussão em 'Python' iniciado por Stack, Junho 6, 2025.

  1. Stack

    Stack Membro Participativo

    Tried this question. I'm running this code locally in Visual Studio Code, and am logged in using az login. I've also tried aad_credentials = AzureCliCredential() with the same result. Left out the details of creating the group.

    aad_credentials = DefaultAzureCredential()
    URI = environ.get("DPS_ENDPOINT")
    client = DeviceProvisioningClient(endpoint=URI, credential=aad_credentials)
    group_id = 'symetric_group_test'
    enrollment_group = {
    "enrollmentGroupId": group_id,
    "attestation": {
    "type": "symmetricKey"
    }
    }
    client.enrollment_group.create_or_update( id=group_id, enrollment_group=enrollment_group


    Response:


    azure.core.exceptions.ClientAuthenticationError: (None) Authorization failed for the request
    Code: None
    Message: Authorization failed for the request
    ​

    adding logging_enable=True did not provide any output.

    Anything hints or directions on how to debug?

    I get the same error in Azure Cloud Shell.

    This might be the issue. I have permissions in portal, but in CLIs:

    az role assignment list --assignee <username>
    []

    Continue reading...

Compartilhe esta Página