DefaultAzureCredential failed to retrieve a token from the included credentials

HASLEHNER, MYLENE 30 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
Azure Machine Learning
An Azure machine learning service for building and deploying models.
3,334 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. YutongTie-MSFT 53,966 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 30 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.

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.