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

Farzane Yahyanejad 30 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,343 questions
{count} vote

1 answer

Sort by: Most helpful
  1. Vikram Singh 2,585 Reputation points Microsoft Employee Moderator
    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.


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.