azure-sdk-for-python: Unable to authenticate to Azure ML Workspace using Service Principal

  • Package Name: azureml-core
  • Package Version: 1.13.0
  • Operating System: Windows 10.0.18363
  • Python Version: 3.6.2

Describe the bug Unable to authenticate to Azure ML Workspace using Service Principal. I get the following error: AttributeError: ‘AdalAuthentication’ object has no attribute ‘get_token’.

To Reproduce Steps to reproduce the behavior:

  1. pip install azureml-core==1.13.0
from azureml.core import Workspace
from azureml.core.authentication import ServicePrincipalAuthentication

tenant = "tenant"
client = "client"
key = "key"

credentials = ServicePrincipalAuthentication(
           tenant_id=tenant,
           service_principal_id=client,
           service_principal_password=key)

workspace = Workspace.from_config("config.json", auth=credentials)

with config.json file containing information about the Workspace.

Expected behavior To be able of attaching to the Workspace using Service Principal.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 12
  • Comments: 37 (12 by maintainers)

Commits related to this issue

Most upvoted comments

It’s not because of AzureML. (downgrading to 1.12.0 causes the same issue.) As @sajalda23409 mentioned it’s related to https://pypi.org/project/azure-mgmt-resource/15.0.0/

Fixed with pinning the previous version: pip install azure-mgmt-resource==10.2.0

Or if you are using Databricks:

if dbutils.library.installPyPI('azure-mgmt-resource', version="10.2.0"):
  dbutils.library.restartPython()

We are taking a look at this issue, and will provide update later For the time being, a workaround is using azure-mgmt-resources 10.2.0 cc @yonzhan @changlong-liu @00Kai0 @jsntcy

On local, workaround from @gison93 work’s perfectly, but I’m using Azure DataBricks as a compute target and cannot change the source code of libraries. I find a solution with downgrade lib azure-mgmt-resource from 15.0.0 to 8.0.1.

You can temporarily fixed with pinning the previous version: pip install azure-mgmt-resource==10.2.0

Workaround/Possible Solution In azure\core\pipeline\policies_authentication.py in class BearerTokenCredentialPolicy instead of calling get_token use _token_retriever() and take the element with index one.

 def on_request(self, request):
        # type: (PipelineRequest) -> None
        """Adds a bearer token Authorization header to request and sends request to next policy.

        :param request: The pipeline request object
        :type request: ~azure.core.pipeline.PipelineRequest
        """
        self._enforce_https(request)
        if self._token is None or self._need_new_token:
            scheme, self._token, _ = self._credential._token_retriever()
        self._update_headers(request.http_request.headers, self._token)

Hi guys, I wanted to provide an update here. The real cause of this behavior is the version upgrade for several Azure service SDKs (such as azure-mgmt-resources and azure-mgmt-network)

Basically, we did a major upgrade for Python SDK management libraries for some services. In the new version of SDK, the authentication mechanism has been changed, we have mentioned those changes in the release notes, please refer to this changelog: changelog

The new version of SDK offers a number of important features but also introduces some breaking changes.

You can either choose to upgrade to the new version or stay on the old version.

To upgrade:

There is migration guide here for updating to the new SDK. This describes the new authentication flow.

Detailed info of benefits of the new SDK as well as documentation/code samples can be found here

To stay on the old version

Please keep using 10.2.0

Please uninstall the azure-mgmt-resource==15.0.0 and azureml-core==1.13.0.

Then install azureml-core==1.13.0.post1. It should fix the issue.

A new version of Azure Mgmt Resource client library released 5 hours ago. Is that caused the issue?

https://pypi.org/project/azure-mgmt-resource/

@gison93 can we use your proposal on microsoft hosted agents?

I think it is easier to roll back to the previous stable version of azure-mgmt-keyvault, i.e. force to use azure-mgmt-keyvault==2.2.0 in the meantime. This seems to solve the issue on my end.

This solution did not work for me.

They are probably changing more stuff at the moment. This did work but it is not working anymore. We will have to wait for a proper fix I guess.

Can confirm @gison93 proposal seems to solve this issue. I don’t fully understand what may have changed if there has been no version update, though.

I suspect is due to the recent update of azure-mgmt-keyvault to version 7.0.0 some hours ago

Hi, I have been using Azure Devops Pipelines with Microsoft Hosted Agents to connect to Azure ML. I am seeing this error “AttributeError: ‘AdalAuthentication’ object has no attribute ‘get_token’”