python - Linux 在 azure 中打印安全组时出错

标签 python azure azure-sdk-python azure-security-center

我有这段代码,并且是在 Windows 中编写的。它在 Windows 中运行良好,但是当我在 Linux 上运行它时,我必须根据我的项目需要在 Linux 上运行它,但它在那里不起作用并给出以下错误

AttributeError: 'ServicePrincipalCredentials' object has no attribute 'get_token'

from azure.mgmt.security import SecurityCenter
from azure.common.credentials import ServicePrincipalCredentials
import Credentials
from pprint import pprint

client = SecurityCenter(Credentials.credential,Credentials.subscription_id,asc_location="")

for score in client.secure_scores.list():
   print(score)

最佳答案

假设您使用的是最新版本的 azure-mgmt-security,它可以与 azure-identity 包配合使用。

例如,您可以使用 from azure.identity import ClientSecretCredentials,而不是 from azure.common.credentials import ServicePrincipalCredentials。

(我在 MS SDK 团队工作)

关于python - Linux 在 azure 中打印安全组时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72321773/

相关文章:

python - 应用程序的自定义 django 管理模板

python - 从字典列表中获取唯一值

azure - 从 Asp.Net Core 中的 URL 中删除附加斜杠

使用 EnvironmentCredential 几乎不可能进行 Azure 量子身份验证

azure - 如何使用 1 年预留实例创建单节点 AKS 集群?

python - Azure QueueClient Python 无法使用 DefaultAzureCredential

python - Azure存储关闭自动解压

python - 如何使用 Selenium (python) 找到这个元素

python - 使用 Kwargs 时可以跳过 Python 中的参数吗

Azure:无法将存档 blob 从一个存储帐户复制到另一个存储帐户?