通过 Python SDK 访问 Azure 容器因 AuthorizationPermissionMismatch 失败,但我是所有者

问题描述 投票:0回答:0

我正在尝试使用 Azure SDK 在 python 脚本中列出 Azure 存储中容器中的 blob。

但是,我收到错误“AuthorizationPermissionMismatch”。

这让我感到惊讶,因为我是容器的所有者:

azure-gui-i-am-owner

我认为我的所有代码都是正确的:

from azure.identity import DefaultAzureCredential
from azure.storage.blob import ContainerClient

if __name__ == "__main__":

    client = ContainerClient(
        credential=DefaultAzureCredential(),
        account_url="https://satestblobaccess.blob.core.windows.net",
        container_name="stcnt-test-blob-access"
    )

    blob_names = client.list_blob_names()
    print([b for b in blob_names])

当我以自己的身份登录时,我在 powershell 中运行此程序,并且 SDK 似乎可以很好地识别我的身份。

所以我希望获得 blob 名称的列表。

相反,我收到了 AuthorizationPermissionMismatch 错误。

如果有人能向我指出如何解决这个问题,那就太好了......

输出是这样的(抱歉,我无法让它显示在 powershell 输出窗口中看到的换行符):

[INFO azure.identity._credentials.environment] 未找到环境配置。 信息:azure.identity._credentials.environment:找不到环境配置。 [INFO azure.identity._credentials.driven_identity] ManagedIdentityCredential 将使用 IMDS 信息:azure.identity._credentials.driven_identity:ManagedIdentityCredential将使用IMDS 信息:azure.core.pipeline.policies.http_logging_policy:请求URL:'http://169.254.169.254/metadata/identity/oauth2/token?api-version=REDACTED&resource=REDACTED' 请求方法:'GET' 请求标头: '用户代理':'azsdk-python-identity/1.15.0 Python/3.10.13 (Windows-10-10.0.19045-SP0)' 请求中未附加正文 DEBUG:urllib3.connectionpool:启动新的 HTTP 连接 (1): 169.254.169.254:80 [INFO azure.identity._credentials.chained] DefaultAzureCredential 从 AzureCliCredential 获取了令牌 信息:azure.identity._credentials.chained:DefaultAzureCredential从AzureCliCredential获取了令牌 信息:azure.core.pipeline.policies.http_logging_policy:请求 URL:'https://satestblobaccess.blob.core.windows.net/stcnt-test-blob-access?restype=REDACTED&comp=REDACTED' 请求方法:'GET' 请求标头: 'x-ms-版本': '已编辑' '接受': '应用程序/xml' '用户代理':'azsdk-python-storage-blob/12.19.0 Python/3.10.13 (Windows-10-10.0.19045-SP0)' 'x-ms-date': '已编辑' 'x-ms-client-request-id': 'f729fa05-19dd-11ef-ae9a-a434d95f5cd9' “授权”:“已编辑” 请求中未附加正文 DEBUG:urllib3.connectionpool:启动新的 HTTPS 连接 (1): satestblobaccess.blob.core.windows.net:443 调试:urllib3.connectionpool:https://satestblobaccess.blob.core.windows.net:443“获取/stcnt-test-blob-access?restype=container&comp=list HTTP/1.1”403 279 信息:azure.core.pipeline.policies.http_logging_policy:响应状态:403 响应头: “内容长度”:“279” '内容类型':'应用程序/xml' “服务器”:“Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0” 'x-ms-request-id': 'fc138e07-a01e-0062-75ea-ad615a000000' 'x-ms-client-request-id': 'f729fa05-19dd-11ef-ae9a-a434d95f5cd9' 'x-ms-版本': '已编辑' 'x-ms-error-code': 'AuthorizationPermissionMismatch' “日期”:“2024 年 5 月 24 日星期五 14:57:44 GMT” 回溯(最近一次调用最后一次): 文件“C:\Users\yrdeb\PycharmProjects est_blob_access_man_ident\main.py”,第 30 行,位于 文件“C:\Users\yrdeb\PycharmProjects est_blob_access_man_ident\main.py”,第 30 行,位于 print([b 代表 blob_names 中的 b]) 文件“C:\Users\yrdeb.conda nvs nv3106\lib\site-packages zur

authorization azure-blob-storage azure-sdk-python
© www.soinside.com 2019 - 2024. All rights reserved.