from azure.identity import DefaultAzureCredential
from azure.keyvault.secrets import SecretClient
# Set up Key Vault client
credential = DefaultAzureCredential()
key_vault_url = "https://abcdefghijklmnop.vault.azure.net/"
secret_client = SecretClient(vault_url=key_vault_url, credential=credential)
# Retrieve the secret
secret_name = "xxxxxxxxxx"
secret = secret_client.get_secret(secret_name).value
print(secret)
我收到以下错误,我这样做对吗?
EnvironmentCredential.get_token failed: EnvironmentCredential authentication unavailable. Environment variables are not fully configured.
ManagedIdentityCredential.get_token failed: ManagedIdentityCredential authentication unavailable, no managed identity endpoint found.
SharedTokenCacheCredential.get_token failed: SharedTokenCacheCredential authentication unavailable. No accounts were found in the cache.
VisualStudioCodeCredential.get_token failed: Failed to get Azure user details from Visual Studio Code.
AzureCliCredential.get_token failed: Azure CLI not found on path
DefaultAzureCredential failed to retrieve a token from the included credentials.
Attempted credentials:
EnvironmentCredential: EnvironmentCredential authentication unavailable. Environment variables are not fully configured.
ManagedIdentityCredential: ManagedIdentityCredential authentication unavailable, no managed identity endpoint found.
SharedTokenCacheCredential: SharedTokenCacheCredential authentication unavailable. No accounts were found in the cache.
VisualStudioCodeCredential: Failed to get Azure user details from Visual Studio Code.
AzureCliCredential: Azure CLI not found on path
---------------------------------------------------------------------------
ClientAuthenticationError Traceback (most recent call last)
Cell In [13], line 11
9 # Retrieve the secret
10 secret_name = "xxxxxxxxxxxxxx"
---> 11 secret = secret_client.get_secret(secret_name).value
12 secret