Azure Python SDK Automation Runbook-错误 - ' clientsEtcretCredential'对象没有属性' signed_session'

发布于 2025-01-23 17:54:03 字数 1596 浏览 5 评论 0原文

我发现与Azure Python错误消息相关的帖子很少 - “ clients otretcredential”对象没有属性'signed_session',但是我正在从Azure Portal中测试我的代码,我正在使用Automation account runbook。我准备了用于更改存储帐户上TLS属性的脚本。我有两个AZ订阅位于不同租户(SUBA-服务提供商,Subb-服务客户)中,我正在使用Azure Lighthouse向SUBA帐户提供Admin访问到Subb。我正在使用Suba Azure AD中注册的SPN。我在笔记本电脑上测试了Python代码,并且所有作品都按预期进行了,我能够使用SUBA SPN -Service Principal修改位于Subb中的存储帐户。我正在从Azure Portal -Automation帐户运行书中测试相同的代码,并且我面临错误self._creds.signed_session(session)attributeError:'clients otretcredential'对象没有属性'signed_session'。在自动化帐户中,我已经导入了包装,在下面列出。

我的Python代码,按照我的笔记本电脑的预期工作,从Azure Portal执行自动化运行手册时,提到了错误。

import sys
import json
from azure.mgmt.resource import SubscriptionClient
from azure.mgmt.resource import ResourceManagementClient
from azure.identity import ClientSecretCredential
import azure.mgmt.storage

subscription_id = "subB-subscriptionID"
tenant_id = "subA-TenantID"
client_id = "subA-clientID"
client_secret = "subA-clientSecret"

credential = ClientSecretCredential(
    tenant_id=tenant_id,
    client_id=client_id,
    client_secret=client_secret)

storage_client = azure.mgmt.storage.StorageManagementClient(
    credentials=credential,
    subscription_id=subscription_id
)

storage_account = storage_client.storage_accounts.update(
    "ResourceGroupName",
    "StorageAccountName",
    {
        "properties": {
            "minimumTlsVersion": "TLS1_2"   
        }
    }
)

I found few posts related to Azure Python error message - 'ClientSecretCredential' object has no attribute 'signed_session', but I am testing my code from Azure portal, I am using Automation Account runbook. I prepared script for changing TLS property on Storage Account. I have two az subscriptions located in different tenants (subA - service provider, subB - service customer), I am using Azure Lighthouse to provide admin access from subA account to subB. I am using SPN registered in subA Azure AD. I tested Python code on my laptop and all works as expected, I was able to modify Storage Account located in subB using subA SPN - Service Principal. I am testing the same code from Azure Portal - Automation Account runbook and I am facing an error self._creds.signed_session(session)AttributeError: 'ClientSecretCredential' object has no attribute 'signed_session'. In Automation Account I have imported packages, list below.

enter image description here

My Python code, works as expected from my Laptop, throwing mentioned error when executing as an automation runbook from Azure Portal.

import sys
import json
from azure.mgmt.resource import SubscriptionClient
from azure.mgmt.resource import ResourceManagementClient
from azure.identity import ClientSecretCredential
import azure.mgmt.storage

subscription_id = "subB-subscriptionID"
tenant_id = "subA-TenantID"
client_id = "subA-clientID"
client_secret = "subA-clientSecret"

credential = ClientSecretCredential(
    tenant_id=tenant_id,
    client_id=client_id,
    client_secret=client_secret)

storage_client = azure.mgmt.storage.StorageManagementClient(
    credentials=credential,
    subscription_id=subscription_id
)

storage_account = storage_client.storage_accounts.update(
    "ResourceGroupName",
    "StorageAccountName",
    {
        "properties": {
            "minimumTlsVersion": "TLS1_2"   
        }
    }
)

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

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

发布评论

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

评论(1

不爱素颜 2025-01-30 17:54:03

我决定使用功能应用程序,而不是自动化运行书。函数包含所有Python代码,所有函数都可以正常工作,我测试了解决方案,所有解决方案都按预期工作。

Instead of Automation runbooks I decided to use Function app. Function contains all Python code and all works fine, I tested the solution and all works as expected.

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