Share via

DefaultAzureCredential failed to retrieve a token from the included credentials

HASLEHNER, MYLENE 35 Reputation points
2023-06-23T12:12:48.78+00:00

When running the notebook lab "Deploy to an batch endpoint" (DP-100 learning path, AzureML SDK v2, learning path "Deploy a model to a managed online endpoint"), I have the following error: DefaultAzureCredential failed to retrieve a token from the included credentials

Is it possible to tell exactly which commands in the notebook need to be written in order to avoid this error, or how to set environment variables?

It is thus impossible to run any of the lab exercises provided by Azure.

Thanks

PS the cell at the beginning cannot be run:

from azure.identity import DefaultAzureCredential, InteractiveBrowserCredential
from azure.ai.ml import MLClient

try:
    credential = DefaultAzureCredential()
    # Check if given credential can get token successfully.
    credential.get_token("https://management.azure.com/.default")
except Exception as ex:
    # Fall back to InteractiveBrowserCredential in case DefaultAzureCredential not work
    credential = InteractiveBrowserCredential()

error: DefaultAzureCredential failed to retrieve a token from the included credentials.
Azure Machine Learning
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. YutongTie-9091 54,021 Reputation points Moderator
    2023-06-24T04:51:01.53+00:00

    Hello @HASLEHNER, MYLENE

    Thanks for reaching out to us.

    The error message you received indicates that the Azure ML SDK was unable to retrieve a token from the included credentials. This can happen if the credentials you are using are invalid or if there is an issue with the authentication process.

    To resolve this issue, you can try the following steps**:**

    Check that you have the correct credentials for your Azure account. You can do this by logging into the Azure portal and checking the credentials for your account.

    If you are using a service principal for authentication, make sure that the service principal has the correct permissions to access the resources you are trying to use.

    Check that your environment variables are set correctly. You can set environment variables in the notebook by using the os module. For example, to set the AZURE_CLIENT_ID environment variable, you can use the following command:

    import os
    os.environ['AZURE_CLIENT_ID'] = '<your-client-id>'
    

    Replace <your-client-id> with the actual client ID for your Azure account.

    If you continue to experience issues, you may want to try using a different authentication method, such as interactive authentication or managed identity.

    It's difficult to say exactly which commands in the notebook need to be written to avoid this error without seeing the notebook itself. However, you can try setting the environment variables as described above and see if that resolves the issue.

    Let me know how it works. I am happy to help you further.

    Regards,

    Yutong

    -Please kindly accept the answer and vote 'Yes' if you feel helpful to support the community, thanks a lot.

    2 people found this answer helpful.

  2. HASLEHNER, MYLENE 35 Reputation points
    2023-06-27T07:24:36.66+00:00

    Hi,

    Thank you for you answer! I cannot find my client ID. The only thing I find is a

    "tenant ID" in the folder Tenant details in Azure Active Directory. Is this the desired ID?

    Thanks

    1 person found this answer helpful.

  3. Xu, Yan 0 Reputation points
    2025-08-31T15:40:18.34+00:00

    I have the same question. I use sdkv2 default client. I can run the python script in local terminal and lunch job in aml without problem. However, i can not use the ADO pipeline to run the python script in job.yml file. I have the similar error message: "

    azure.ai.ml.exceptions.MlException: {
      "result": "Failed",
      "errors": [
        {
          "message": "DefaultAzureCredential failed to retrieve a token from the included credentials.\nAttempted credentials:\n\tEnvironmentCredential: EnvironmentCredential authentication unavailable. Environment variables are not fully configured.\nVisit https://aka.ms/azsdk/python/identity/environmentcredential/troubleshoot to troubleshoot this issue.\n\tManagedIdentityCredential: string indices must be integers\nTo mitigate this issue, please refer to the troubleshooting guidelines here at https://aka.ms/azsdk/python/identity/defaultazurecredential/troubleshoot.",
          "path": "compute",
          "value": "azureml:gpu-cluster"
        }
      ]
    }
    

    "

    0 comments No comments

Your answer

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