我无法从 msrestazure.azure 包 python 创建 ServicePrincipleCredentials 的凭据实例

I'm unable to create a credentials instance of ServicePrincipleCredentials from the msrestazure.azure package python

我正在尝试连接到 azure keyvault,但我无法创建访问任何机密的凭据。当我调用代码时:

    TENANT_ID = os.environ.get("key")
    CLIENT = os.environ.get("key")
    KEY = os.environ.get("key")

    credentials = ServicePrincipalCredentials(
        client_id = CLIENT,
        secret = KEY,
        tenant = TENANT_ID
    ) 

我收到以下错误:

  File "file here", line 355, in __init__
    self.set_token()
  File "file here", line 362, in set_token
    super(ServicePrincipalCredentials, self).set_token()
  File "file here", line 188, in set_token
    self._create_adal_context()
  File "file here", line 109, in _create_adal_context
    authority_url = authority_url + '/' + self._tenant
TypeError: can only concatenate str (not "NoneType") to str

我已经仔细检查了密钥的正确性非常感谢任何想法或帮助谢谢。

我想通了这个问题。我使用的是不再有效的旧软件包。 msrestazure.azure_active_directory 不再使用 我不得不使用 azure.common.credentials

@HHammond 我们已经为 KeyVault 发布了一个新的库,它将使对服务的身份验证更加容易(除其他外)。

您可以在 PyPI 上找到新库:https://pypi.org/project/azure-keyvault/

以下是一些可以帮助您入门的示例:https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/keyvault/azure-keyvault-keys/samples