azure.core.exceptions.ClientAuthenticationError: DefaultAzureCredential failed to retrieve a token from the included credentials.

Diksha Singh 60 Reputation points
2023-09-27T19:10:09.7366667+00:00

from azure.identity import DefaultAzureCredential

from azure.mgmt.network import NetworkManagementClient

import time

credential = DefaultAzureCredential()

network_client = NetworkManagementClient(credential, subscription_id)

network_interface = network_client.network_interfaces.get(resource_group, nic_name)

Using the above code I was trying to read network details, but I am getting the below error

File "/usr/lib/python3/dist-packages/azure/identity/_credentials/chained.py", line 111, in get_token
    raise ClientAuthenticationError(message=message)
azure.core.exceptions.ClientAuthenticationError: DefaultAzureCredential failed to retrieve a token from the included credentials.
Attempted credentials:
        EnvironmentCredential: EnvironmentCredential authentication unavailable. Environment variables are not fully configured.
Visit https://aka.ms/azsdk/python/identity/environmentcredential/troubleshoot to troubleshoot this issue.
        ManagedIdentityCredential: ManagedIdentityCredential authentication unavailable, no response from the IMDS endpoint.
        SharedTokenCacheCredential: Shared token cache unavailable
        AzureCliCredential: Azure CLI not found on path
        AzurePowerShellCredential: PowerShell is not installed
        AzureDeveloperCliCredential: Azure Developer CLI could not be found. Please visit https://aka.ms/azure-dev for installation instructions and then,once installed, authenticate to your Azure account using 'azd auth login'.
To mitigate this issue, please refer to the troubleshooting guidelines here at https://aka.ms/azsdk/python/identity/defaultazurecredential/troubleshoot.
-bash-5.0#

The roles I have :

User's image

Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
21,797 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Akshay-MSFT 17,866 Reputation points Microsoft Employee
    2023-09-29T14:33:53.3366667+00:00

    @Diksha Singh

    Thank you for posting your query on Microsoft Q&A, the above shared indicates that the DefaultAzureCredential object was unable to obtain a valid authentication token from any of the available credential sources.

    From above error it seems that the EnvironmentCredential object was unable to obtain a valid authentication token from the environment variables.

    EnvironmentCredential: EnvironmentCredential authentication unavailable. Environment variables are not fully configured.

    Kindly validate the following:

    Ensure the appropriate environment variables are set prior to application startup for the intended authentication method and this has appropriate permissions assigned.

    • To authenticate a service principal using a client secret, ensure the variables AZURE_CLIENT_ID, AZURE_TENANT_ID and AZURE_CLIENT_SECRET are properly set.
    • To authenticate a service principal using a certificate, ensure the variables AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_CERTIFICATE_PATH, and optionally AZURE_CLIENT_CERTIFICATE_PASSWORD are properly set.
    • To authenticate a user using a password, ensure the variables AZURE_USERNAME and AZURE_PASSWORD are properly set

    Still if this does not work then, Please install developer CLI, once installed, authenticate to your Azure account using 'azd auth login', this will get the access token from AzureDeveloperCliCredential.

    Please do let me know if you have any further queries.

    Thanks,

    Akshay Kaushik

    Please "Accept the answer" (Yes), and share your feedback if the suggestion answers you’re your query. This will help us and others in the community as well.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.