Meet Bardoliya
Meet Bardoliya

Reputation: 13

ClientAuthenticationError: DefaultAzureCredential failed to retrieve a token from the included credentials

I am encountering an error while trying to register a model in the Azure ML Workspace. The error occurs in the following code snippet:

model = Model.register(
    model_path="***",
    model_name="***",
    tags={},
    description="***",
    workspace=***
)

The error message I am receiving is:

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: Expecting value: line 1 column 1 (char 0) To mitigate this issue, please refer to the troubleshooting guidelines here at https://aka.ms/azsdk/python/identity/defaultazurecredential/troubleshoot.

Any suggestion would be appreciated. Thanks in Advance!

Upvotes: 0

Views: 59

Answers (1)

JayashankarGS
JayashankarGS

Reputation: 7985

You are getting authentication issue, by default the Workspace object uses InteractiveLoginAuthentication authentication.

enter image description here

The same is passed while registering the model.

So, create workspace object again, below are some alternatives you can try.

  1. MSI Authentication

from azureml.core.authentication import MsiAuthentication

msi_auth = MsiAuthentication()

ws = Workspace(subscription_id="my-subscription-id",
               resource_group="my-ml-rg",
               workspace_name="my-ml-workspace",
               auth=msi_auth)
  1. InteractiveLoginAuthentication

from azureml.core.authentication import InteractiveLoginAuthentication

interactive_auth = InteractiveLoginAuthentication(tenant_id="my-tenant-id")

ws = Workspace(subscription_id="my-subscription-id",
               resource_group="my-ml-rg",
               workspace_name="my-ml-workspace",
               auth=interactive_auth)

You should be getting token when you run any of the below codes.

from azureml.core.authentication import MsiAuthentication,InteractiveLoginAuthentication

print(MsiAuthentication().get_token())

print(InteractiveLoginAuthentication().get_token())

enter image description here

Check this notebook on more about authentications.

Upvotes: 0

Related Questions