Problems connecting to workspace using Azure Machine Learning SDK for Python

Rachael Fletcher 26 Reputation points
2020-11-22T22:10:56.563+00:00

I am trying to connect to my Azure ML workspace using SDK for python, using Virtual Studio Code to do so. After pip installing the needed SDK packages:
pip install azureml-sdk
pip install azureml-sdk[notebooks,automl,explain]

I downloaded the .json configuration file for my workspace, made sure it was in the correct location for the file path and tried the following code (with my subscription id, resource group and workspace name in place of the fillers in this chunk of code):

{  
    "subscription_id": "1234567-abcde-890-fgh...",  
    "resource_group": "aml-resources",  
    "workspace_name": "aml-workspace"  
}  

Upon executing this in my ipy kernel in Virutal Studio Code I got a UserErrorException (see image below, I have blocked out subscription id's and other sensitive information):

41683-subscriptionerror.png

I then tried this alternative way to connect to my workspace using the following code (again with my info filled in instead of the fillers in the code):
from azureml.core import Workspace

from azureml.core import Workspace  
  
ws = Workspace.get(name='aml-workspace',  
                   subscription_id='1234567-abcde-890-fgh...',  
                   resource_group='aml-resources')  
  
ws = Workspace.from_config()  

This produced the same error upon execution. I have tried using different subscriptions with different workspace names and resource groups and it gives me the same error every time. It appears to be telling me I do not have access to the subscription that I am logged in to? I am unsure how to fix this. I am trying to do this as part of the lessons in the Microsoft Azure Data Scientist certification if anyone is familiar with that or has run into the same problem while trying to complete the modules for that certification provided through Microsoft.

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,820 questions
Azure Machine Learning
Azure Machine Learning
An Azure machine learning service for building and deploying models.
2,551 questions
0 comments No comments
{count} votes

Accepted answer
  1. kalyan reddy 186 Reputation points
    2020-11-23T02:07:42.373+00:00

    can you try using InteractiveLoginAuthentication?

    below code might help you

    from azureml.core.authentication import InteractiveLoginAuthentication
    ia = InteractiveLoginAuthentication(tenant_id='YourTenant id')
    # You can find tenant id under azure active directory->properties
    ws = Workspace.get(name='aml-workspace',
                        subscription_id='1234567-abcde-890-fgh...',
                        resource_group='aml-resources',auth=ia)
    
    3 people found this answer helpful.

4 additional answers

Sort by: Most helpful
  1. Samad 21 Reputation points
    2020-12-17T09:25:40.42+00:00

    Hello,
    I have the same problem. I tried InteractiveLoginAuthentication first but I had this error :

    "error": {
    "message": "No workspaces found with name=projet7 in subscription=d9b1b5ff-XXX-XXXX-XXXX-XXXXXXXXXXXX"
    }

    ia = InteractiveLoginAuthentication(tenant_id='712a4781-YYYY-YYYY-YYYY-YYYYYYYYYYYY')
    ws = Workspace.get(name='Projet7',
    subscription_id='d9b1b5ff-XXX-XXXX-XXXX-XXXXXXXXXXXX',
    resource_group='classroom',auth=ia)

    I'm using a virtual machine azure sku='server-2019'; Python 3.6 - AzureML - AutoML


  2. Samad 21 Reputation points
    2020-12-18T19:46:23.42+00:00

    I have already created Project7 by portal.

    I tried to create a new one.

    ia = InteractiveLoginAuthentication(tenant_id="712a4781-YYYY-YYYY-YYYY-YYYYYYYYYYYY")
    ws = Workspace.create(name='RNN_workspace',
    subscription_id='/subscriptions/d9b1b5ff-XXX-XXXX-XXXX-XXXXXXXXXXXX',
    resource_group='classroom',
    create_resource_group=False,
    location='West Europe',
    auth=ia
    )

    but I had the same error :

    UserErrorException: UserErrorException:
    Message: You are currently logged-in to 712a4781-YYYY-YYYY-YYYY- tenant. You don't have access to /subscriptions/d9b1b5ff-XXX-XXXX-XXXX-XXXXXXXXXXXX subscription, please check if it is in this tenant. All the subscriptions that you have access to in this tenant are =
    [SubscriptionInfo(subscription_name='Microsoft Azure ffffff', subscription_id='d9b1b5ff-XXX-XXXX-XXXX-'), SubscriptionInfo(subscription_name='Lab 2 - Extension name_axtension', subscription_id='59383c45-MMMM-MMMM-')].

    0 comments No comments

  3. Samad 21 Reputation points
    2020-12-18T20:17:50.353+00:00

    !az login
    [
    {
    "cloudName": "AzureCloud",
    "homeTenantId": "712a4781-YYYY-YYYY-YYYY-YYYYYYYYYYYY",

    You have logged in. Now let us find all the subscriptions to which you have access...
    The following tenants don't contain accessible subscriptions. Use 'az login --allow-no-subscriptions' to have tenant level access.
    c9587321-JJJJ-JJJJ-JJJJ-JJJJJJJJJJJJ

    "id": "d9b1b5ff-XXX-XXXX-XXXX-XXXXXXXXXXXX",
    "isDefault": true,
    "managedByTenants": [],
    "name": "Microsoft Azure MMMM",
    "state": "Enabled",
    "tenantId": "712a4781-YYYY-YYYY-YYYY-YYYYYYYYYYYY",
    "user": {
      "name": "adress",
      "type": "user"
    }
    

    },
    {
    "cloudName": "AzureCloud",
    "homeTenantId": "712a4781-YYYY-YYYY-YYYY-YYYYYYYYYYYY",
    "id": "59383c45-RRRR-RRRR-RRRR-RRRRRRRRRRRR",
    "isDefault": false,
    "managedByTenants": [],
    "name": "Lab 2 - Extension RRRRR",
    "state": "Enabled",
    "tenantId": "712a4781-YYYY-YYYY-YYYY-YYYYYYYYYYYY",
    "user": {
    "name": "adress",
    "type": "user"
    }
    }
    ]

    !az account show
    {
    "environmentName": "AzureCloud",
    "homeTenantId": "712a4781-YYYY-YYYY-YYYY-YYYYYYYYYYYY",
    "id": "d9b1b5ff-XXX-XXXX-XXXX-XXXXXXXXXXXX",
    "isDefault": true,
    "managedByTenants": [],
    "name": "Microsoft Azure MMMM",
    "state": "Enabled",
    "tenantId": "712a4781-YYYY-YYYY-YYYY-YYYYYYYYYYYY",
    "user": {
    "name": "adress",
    "type": "user"
    }
    }

    I don't undestand why my tenant id can't contain accessible subscriptions !!

    0 comments No comments

  4. Chengyu Liu 1 Reputation point
    2021-02-10T11:40:37.92+00:00

    I have the same issue and my previous colleague had the same issue in his laptop. My previous colleague called support for help and solved the problem. But the solution MS support provided was not permanent. What MS support provided was to use interactive mode to clear caching and user information. But in the production development environment people cannot use interactive mode all the time to clear caching.

    Now I am having the same issue but in production environment. When switching subscriptions, somehow python sdk can not fetch new list of subscription ids. I have been added to this particular subscription for more than a week. Couldnot say my account was added "recently".

    I feel this is a bug.

    ServicePrincipalAuthentication(tenant_id=tenant_id,
                        service_principal_id=service_principal_id,
                        service_principal_password=service_principal_password,
                        _enable_caching=False)
    Workspace.get('workspace',
                        subscription_id='subscription_id',
                        resource_group='resource_group',
                        auth=sp)
    

    I created an issue in the GitHub where azure ml related are discussed.