如何解决AzureClicredential的问题?

发布于 2025-02-13 02:53:40 字数 546 浏览 2 评论 0原文

以下是我的代码,在Linux中,我已通过AZ登录登录到Azure,但是当我尝试运行以下代码时,它会给我一个错误

(最新调用最后): 文件“ scan.py”,第1行,in 从azure.Identimity导入AzureCrecredential

I还安装了PIP安装Azure-Identity,但仍然相同。

#CODE#

from azure.identity import AzureCliCredential
from azure.mgmt.subscription import SubscriptionClient
import json


credential = AzureCliCredential()
subscription_client = SubscriptionClient(credential)
sub_list = subscription_client.subscriptions.list()

for sub in list(sub_list):
    subs_id = sub.subscription_id
    print(subs_id)

The following is my code and in linux I have logged in to azure via az login but when I try to run the below code it gives me an error that

Traceback (most recent call last):
File "scan.py", line 1, in
from azure.identity import AzureCliCredential

I also installed the pip install azure-identity but its still the same.

#CODE#

from azure.identity import AzureCliCredential
from azure.mgmt.subscription import SubscriptionClient
import json


credential = AzureCliCredential()
subscription_client = SubscriptionClient(credential)
sub_list = subscription_client.subscriptions.list()

for sub in list(sub_list):
    subs_id = sub.subscription_id
    print(subs_id)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

马蹄踏│碎落叶 2025-02-20 02:53:40

Glad @ Ghostrider 您自己解决了问题。

如您没有提及哪种版本的Python,您正在使用,但是现在通过使用Python 3来解决。

我还在使用Python 3.9版本的本地VS代码中运行此代码,并获得了成功的结果:

“

,也观察到代码中存在的软件包Azure-Indentity由Python版本3.6或最新版本支持,如 Python包装库官方网站

Glad @Ghostrider that you had resolved the issue yourself.

As you did not mention what version of python, you're using earlier, but for now resolved by using python 3.

I also run this code in my local VS Code with the Python 3.9 Version and got the successful result:

VSCodeRun

Also, observed the packages present in the code that the package azure-identity is supported from Python Version 3.6 or the latest versions, as given in the Python Packages Library Official Site.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文