How to fix "ClientAuthenticationError" in Azure ai machine learning studio

Tian Yi (XC-AD/EFB2-NA) 0 Reputation points
2024-09-06T21:20:39.77+00:00

I am trying to run the sample code for "Quickstart: Get started with Azure Machine Learning" in Azure ai, Machine Learning Studio and sees the following error about credential:

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/troubleshootto troubleshoot this issue. ManagedIdentityCredential: Unexpected response "{'error': 'SSO failure, to mitigated it please try to click Jupyter/JupyterLab.'}" Content: {"error":"SSO failure, to mitigated it please try to click Jupyter/JupyterLab."} To mitigate this issue, please refer to the troubleshooting guidelines here athttps://aka.ms/azsdk/python/identity/defaultazurecredential/troubleshoot.

Code looks like this:

credential = DefaultAzureCredential(exclude_shared_token_cache_credential=True)

SUBSCRIPTION = "xxx"
RESOURCE_GROUP = "xxx"
WS_NAME = "xxx"

# Get a handle to the workspace
ml_client = MLClient(
    credential=credential,
    subscription_id=SUBSCRIPTION,
    resource_group_name=RESOURCE_GROUP,
    workspace_name=WS_NAME,
    logging_enable=True
)
Azure Machine Learning
Azure Machine Learning
An Azure machine learning service for building and deploying models.
2,914 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. romungi-MSFT 46,056 Reputation points Microsoft Employee
    2024-09-09T05:33:37.4633333+00:00

    @Tian Yi (XC-AD/EFB2-NA) I think you have not authenticated before this step in your notebook so the error is seen. Ideally, if you are running for the first time, try to authenticate with interactive mode and then use the subscription, resource group and workspace name. See this notebook on how you can set it up from the first two cells. To fix this issue run the below and check if it works.

    from azure.identity import DefaultAzureCredential, InteractiveBrowserCredential
    
    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
        # This will open a browser page for
        credential = InteractiveBrowserCredential()
    
    
    

    If it does not work, the other way is to use the config from JSON as mentioned in the second cell of the referenced notebook. Try downloading the config.json from your ML studio and place it in the same path as notebook and run the MLClient to pickup this file.

    User's image

    Download the file and use it and use it from a path as mentioned in the second cell of the referenced notebook.

    ml_client = MLClient.from_config(credential=credential, path=config_path)
    print(ml_client)
    

    If this answers your query, do click Accept Answer and Yes for was this answer helpful. And, if you have any further query do let us know.


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.