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.
install-the-package-authenticate-client
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"
}
run.py:
from azureml.core import Workspace
from azure.identity import DefaultAzureCredential
SUBSCRIPTION_ID = 'YOUR_SUBSCRIPTION_ID'
RESOURCE_GROUP_NAME = 'YOUR_RESOURCE_GROUP'
WORKSPACE_NAME = 'YOUR_WORKSPACE_NAME'
# Authenticate using DefaultAzureCredential
credential = DefaultAzureCredential()
# Get a handle to the workspace
# Get a handle to the workspace
ws = Workspace.from_config()
print(ws)
from azure.ai.ml import MLClient
ml_client = MLClient(
DefaultAzureCredential(), SUBSCRIPTION_ID, RESOURCE_GROUP_NAME, WORKSPACE_NAME
)
ws1 = ml_client.workspaces.get(WORKSPACE_NAME)
print(ws1.location, ':', ws1.resource_group)
Execute run.py in terminal:
I trust that the information provided will assist you in identifying the problem at your end.
Thank you.