'ImportError: cannot import name 'AccessTokenInfo' from 'azure.core.credentials'

Farzane Yahyanejad 0 Reputation points Microsoft Employee
2025-02-06T17:26:50.4366667+00:00

I'm trying to execute python script using this tutorial https://learn.microsoft.com/en-us/azure/machine-learning/component-reference/execute-python-script?view=azureml-api-2&viewFallbackFrom=azureml-api-1
but I keep receiving

azureml_main: 'ImportError: cannot import name 'AccessTokenInfo' from 'azure.core.credentials'

I checked and I am using azure-core-1.32.0, which it should have 'AccessTokenInfo', but I keep receiving this!

This error happens when I import "from azure.keyvault.secrets import SecretClient"

Azure Machine Learning
Azure Machine Learning
An Azure machine learning service for building and deploying models.
3,115 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Vikram Singh 1,630 Reputation points Microsoft Employee
    2025-02-07T05:48:55.05+00:00

    Hi Farzane Yahyanejad,

    Welcome to the Microsoft Q&A Forum! Thank you for posting your query here.

    The ImportError: cannot import name 'AccessTokenInfo' from 'azure.core.credentials' occurs because the AccessTokenInfo class was introduced in version 1.33.0 of the azure-core library. Since you're using version 1.32.0, this class isn't available, leading to the import error when your script attempts to import SecretClient from azure.keyvault.secrets.

    To resolve this issue, upgrade your azure-core library to version 1.33.0 or later. You can do this by running the following command:

    pip install --upgrade azure-core
    

    After upgrading, ensure that your script is using the correct version by adding the following lines to your script:

    import azure.core
    print(azure.core.__version__)
    

    This will print the version of azure-core being used, allowing you to confirm that the upgrade was successful.

    For more, you can refer to the official Microsoft documentation: AccessTokenInfo

    I hope this is helpful! Do let me know if you are still the facing the issue.

    Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.


  2. Farzane Yahyanejad 0 Reputation points Microsoft Employee
    2025-02-11T21:29:27.3066667+00:00

    No this is not true. The latest version of Azure core is 1.32.0. Code is working fine in my notebook in AML. but when I use executing python script from this doc https://learn.microsoft.com/en-us/azure/machine-learning/component-reference/execute-python-script?view=azureml-api-2&viewFallbackFrom=azureml-api-1 I receive this error. The error happens once I import package azure.keyvault.secrets which I need this package in my code. Without importing the keyvault package I don't receive the error and azure core 1.32.0 is working fine. I don't know what's happening after installing azure.keyvault.secrets

    0 comments No comments

  3. Farzane Yahyanejad 0 Reputation points Microsoft Employee
    2025-02-11T21:29:53.74+00:00

    No this is not true. The latest version of Azure core is 1.32.0. Code is working fine in my notebook in AML. but when I use executing python script from this doc https://learn.microsoft.com/en-us/azure/machine-learning/component-reference/execute-python-script?view=azureml-api-2&viewFallbackFrom=azureml-api-1 I receive this error. The error happens once I import package azure.keyvault.secrets which I need this package in my code. Without importing the keyvault package I don't receive the error and azure core 1.32.0 is working fine. I don't know what's happening after installing azure.keyvault.secrets

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.