Troubleshooting “User does not exist in MSAL token cache. Run az login” Azure Interactive login error in Python

AKshay Raut
1 min readAug 4, 2024

--

from azureml.core import Workspace
from azureml.core.authentication import InteractiveLoginAuthentication

# # Function to setup Azure ML workspace
def setup_azure_workspace(subscription_id, resource_group, workspace_name):
try:
interactive_auth = InteractiveLoginAuthentication()
ws = Workspace(subscription_id, resource_group, workspace_name, auth=interactive_auth)
print('Workspace configuration completed')
print(ws.name, ws.location, ws.resource_group, ws.subscription_id, sep='\t')
return ws
except Exception as e:
print(f"Failed to set up Azure ML workspace: {e}")
return None

You get an error like this:

Failed to set up Azure ML workspace: AzureMLException:
Message: User rakshay08@gmail.com does not exist in MSAL token cache. Run `az login`.
InnerException None
ErrorResponse
{
"error": {
"message": "User rakshay08@gmail.com does not exist in MSAL token cache. Run `az login`."
}
}

What’s happening here?

This line opens up a new browser window for you to signin:

interactive_auth = InteractiveLoginAuthentication()

You can view the console output as:

Backend TkAgg is interactive backend. Turning interactive mode on.
Performing interactive authentication. Please follow the instructions on the terminal.
The default web browser has been opened at https://login.microsoftonline.com/organizations/oauth2/v2.0/authorize. Please continue the login in the web browser. If no web browser is available or if the web browser fails to open, use device code flow with `az login --use-device-code`.

Solution:
You need to specify the tenant ID in the InteractiveLoginAuthentication like so: Replace the <tenant-id> with your Tenant ID.

interactive_auth = InteractiveLoginAuthentication(tenant_id='<tenant-id>')

Reference: https://stackoverflow.com/a/63156401/4106558

--

--

AKshay Raut
AKshay Raut

Written by AKshay Raut

Solution developer, Workaholic

No responses yet