Skip to content

failed to retrieve a token from the included credential #31648

@jrothwellras

Description

@jrothwellras

Describe the bug

I randomly get this error message:

DefaultAzureCredential failed to retrieve a token from the included credentials. Attempted credentials: EnvironmentCredential: EnvironmentCredential authentication unavailable. Environment variables are not fully configured.

When I do the az login command, I can authenticate fine for about 24 hours, then this error starts popping up again until i reauthenticate.

Related command

credential = DefaultAzureCredential()

Errors

stderr='DefaultAzureCredential failed to retrieve a token from the included credentials.\nAttempted credentials:\n\tEnvironmentCredential: EnvironmentCredential authentication unavailable. Environment variables are not fully configured.\nVisit https://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Faka.ms%2Fazsdk%2Fpython%2Fidentity%2Fenvironmentcredential%2Ftroubleshoot&data=05%7C02%7Cjrothwell%40coresupply.com%7Cd4fb3d9212e840f3415608dda41814ea%7Ccced47230796475dbff35e9b6ad87138%7C1%7C0%7C638847145518905760%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=xyWBYIBKifS8MNh%2B%2BaERvJ5YnRbKcjJqOPPXkn6GSCU%3D&reserved=0 to troubleshoot this issue.\n\tManagedIdentityCredential: ManagedIdentityCredential authentication unavailable, no response from the IMDS endpoint. invalid_request\n\tSharedTokenCacheCredential: SharedTokenCacheCredential authentication unavailable. No accounts were found in the cache.\n\tAzureCliCredential: Failed to invoke the Azure CLI\n\tAzurePowerShellCredential: PowerShell is not installed\n\tAzureDeveloperCliCredential: Azure Developer CLI could not be found. Please visit https://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Faka.ms%2Fazure-dev&data=05%7C02%7Cjrothwell%40coresupply.com%7Cd4fb3d9212e840f3415608dda41814ea%7Ccced47230796475dbff35e9b6ad87138%7C1%7C0%7C638847145518920733%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=IdH%2BwBhP7MhHPUfwlQ6dBCnih4bc0yzaJnnRhVNZkjw%3D&reserved=0 for installation instructions and then,once installed, authenticate to your Azure account using 'azd auth login'.\nTo mitigate this issue, please refer to the troubleshooting guidelines here at https://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Faka.ms%2Fazsdk%2Fpython%2Fidentity%2Fdefaultazurecredential%2Ftroubleshoot.%2FnDefaultAzureCredential&data=05%7C02%7Cjrothwell%40coresupply.com%7Cd4fb3d9212e840f3415608dda41814ea%7Ccced47230796475dbff35e9b6ad87138%7C1%7C0%7C638847145518930145%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=JccXhrgCiL4QDtKhklNPjIdnYlYxpLH%2BKLeMJWvdkcU%3D&reserved=0 failed to retrieve a token from the included credentials.\nAttempted credentials:\n\tEnvironmentCredential: EnvironmentCredential authentication unavailable. Environment variables are not fully configured.\nVisit https://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Faka.ms%2Fazsdk%2Fpython%2Fidentity%2Fenvironmentcredential%2Ftroubleshoot&data=05%7C02%7Cjrothwell%40coresupply.com%7Cd4fb3d9212e840f3415608dda41814ea%7Ccced47230796475dbff35e9b6ad87138%7C1%7C0%7C638847145518939672%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=ae20nUe%2BNZlHvxNgC8hKib7ZI9rFgTzd9MMVXSyjoXI%3D&reserved=0 to troubleshoot this issue.\n\tManagedIdentityCredential: ManagedIdentityCredential authentication unavailable, no response from the IMDS endpoint. invalid_request\n\tSharedTokenCacheCredential: SharedTokenCacheCredential authentication unavailable. No accounts were found in the cache.\n\tAzureCliCredential: Please run 'az login' to set up an account\n\tAzurePowerShellCredential: PowerShell is not installed\n\tAzureDeveloperCliCredential: Azure Developer CLI could not be found. Please visit https://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Faka.ms%2Fazure-dev&data=05%7C02%7Cjrothwell%40coresupply.com%7Cd4fb3d9212e840f3415608dda41814ea%7Ccced47230796475dbff35e9b6ad87138%7C1%7C0%7C638847145518949473%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=I3iXgq3LHMhRy%2Feh4S3hcgZiWvc8Sfld14WXhyGkdvw%3D&reserved=0 for installation instructions and then,once installed, authenticate to your Azure account using 'azd auth login'.\nTo mitigate this issue, please refer to the troubleshooting guidelines here at https://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Faka.ms%2Fazsdk%2Fpython%2Fidentity%2Fdefaultazurecredential%2Ftroubleshoot.%2FnDefaultAzureCredential&data=05%7C02%7Cjrothwell%40coresupply.com%7Cd4fb3d9212e840f3415608dda41814ea%7Ccced47230796475dbff35e9b6ad87138%7C1%7C0%7C638847145518958620%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=sm8suO3o5bRq1NzPsU7whu5aSXw3LPSdAIwTHVxqp44%3D&reserved=0 failed to retrieve a token from the included credentials.\nAttempted credentials:\n\tEnvironmentCredential: EnvironmentCredential authentication unavailable. Environment variables are not fully configured.\nVisit https://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Faka.ms%2Fazsdk%2Fpython%2Fidentity%2Fenvironmentcredential%2Ftroubleshoot&data=05%7C02%7Cjrothwell%40coresupply.com%7Cd4fb3d9212e840f3415608dda41814ea%7Ccced47230796475dbff35e9b6ad87138%7C1%7C0%7C638847145518967944%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=EYcUbng2GS%2FCGiJotwLCqSKVL03nzoXJ%2B%2Fq8exVFK8Y%3D&reserved=0 to troubleshoot this issue.\n\tManagedIdentityCredential: ManagedIdentityCredential authentication unavailable, no response from the IMDS endpoint. invalid_request\n\tSharedTokenCacheCredential: SharedTokenCacheCredential authentication unavailable. No accounts were found in the cache.\n\tAzureCliCredential: Please run 'az login' to set up an account\n\tAzurePowerShellCredential: PowerShell is not installed\n\tAzureDeveloperCliCredential: Azure Developer CLI could not be found. Please visit https://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Faka.ms%2Fazure-dev&data=05%7C02%7Cjrothwell%40coresupply.com%7Cd4fb3d9212e840f3415608dda41814ea%7Ccced47230796475dbff35e9b6ad87138%7C1%7C0%7C638847145518977778%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=kwqFmZauNxE6Xyin9jAKrsxuMjlT1mgXPSFmxSKntHM%3D&reserved=0 for installation instructions and then,once installed, authenticate to your Azure account using 'azd auth login'.\nTo mitigate this issue, please refer to the troubleshooting guidelines here at https://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Faka.ms%2Fazsdk%2Fpython%2Fidentity%2Fdefaultazurecredential%2Ftroubleshoot.%2FnDefaultAzureCredential&data=05%7C02%7Cjrothwell%40coresupply.com%7Cd4fb3d9212e840f3415608dda41814ea%7Ccced47230796475dbff35e9b6ad87138%7C1%7C0%7C638847145518987028%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=PFtoO%2Bo0dzcoTV4Hh%2Fw3wo%2FtPrhTthB178YaNWJYLeg%3D&reserved=0 failed to retrieve a token from the included credentials.\nAttempted credentials:\n\tEnvironmentCredential: EnvironmentCredential authentication unavailable. Environment variables are not fully configured.\nVisit

Issue script & Debug output

N/A expected behavior comes after azure cli is authenticated.

Expected behavior

Authentication to azure blob storage to upload files via python.

Environment Summary

azure-cli 2.74.0

core 2.74.0
telemetry 1.1.0

Dependencies:
msal 1.32.3
azure-mgmt-resource 23.3.0

Python location 'C:\Program Files\Microsoft SDKs\Azure\CLI2\python.exe'
Config directory 'C:\Users\tpegge.azure'
Extensions directory 'C:\Users\tpegge.azure\cliextensions'

Python (Windows) 3.12.10 (tags/v3.12.10:0cc8128, Apr 8 2025, 12:21:36) [MSC v.1943 64 bit (AMD64)]

Legal docs and information: aka.ms/AzureCliLegal

Your CLI is up-to-date.

Additional context

This is executed via a python script.

Metadata

Metadata

Assignees

Labels

Accountaz login/accountAuto-AssignAuto assign by botPossible-SolutionSDK Issuesdk side issueSimilar-Issueact-identity-squadcustomer-reportedIssues that are reported by GitHub users external to the Azure organization.questionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions