mlclient DefaultAzureCredential failed to retrieve a token from the included credentials.

Richard Gross 0 Reputation points


I followed the azure machine learning sample code, however mlclient failed to retrieve a token from the included credentials..

Screenshot is attached.

User's image

User's image


Azure Machine Learning
Azure Machine Learning
An Azure machine learning service for building and deploying models.
2,608 questions
{count} votes

1 answer

Sort by: Most helpful
  1. dupammi 7,305 Reputation points Microsoft Vendor

    Hi @Richard Gross

    Thank you for reaching out to us.

    The error message you encountered suggests that the Azure ML SDK failed to retrieve a token from the provided credentials. This error can occur due to invalid credentials or an issue with the authentication process.

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

    Ensure that you have the accurate credentials for your Azure account by logging into the Azure portal and verifying the credentials associated with your account. In case you are using a service principal for authentication, ensure that the service principal has the appropriate permissions to access the resources you intend 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.

    credential = ManagedIdentityCredential(client_id="CLIENT_ID_OF_MANAGED_IDENTITY_ASSIGNED_TO_WORKSPACE")

    It's difficult to say exactly which commands in the notebook need to be written to avoid this error without seeing the notebook itself. Nevertheless, you can attempt to resolve the issue by following the steps mentioned earlier to set the environment variables.

    For more information on how to set up the credentials for Azure Machine Learning, please refer to the following documentation:

    By following the steps outlined in the documentation below, I could run the script without any issues.




    Here is what I attempted using the config.json, and it worked correctly on my end.

    My config.json :

        "subscription_id": "YOUR_SUBSCRIPTION_ID",
        "resource_group": "YOUR_RESOURCE_GROUP",
        "workspace_name": "YOUR_WORKSPACE_NAME"

    from azureml.core import Workspace
    from azure.identity import DefaultAzureCredential
    # Authenticate using DefaultAzureCredential
    credential = DefaultAzureCredential()
    # Get a handle to the workspace
    # Get a handle to the workspace
    ws = Workspace.from_config()               
    from import MLClient
    ml_client = MLClient(
    ws1 = ml_client.workspaces.get(WORKSPACE_NAME)
    print(ws1.location, ':', ws1.resource_group)

    Execute in terminal:
    User's image

    I trust that the information provided will assist you in identifying the problem at your end.

    Thank you.

    0 comments No comments