You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用Python SDK获取Azure Blob Storage版本启用设置?

如何通过Python SDK获取Blob存储的版本启用状态

你执行Azure CLI命令az storage account blob-service-properties show --account-name sa36730 --resource-group rg-exercise1时能拿到isVersioningEnabled字段,但调用Blob Storage SDK的get_service_properties()却获取不到对应信息,核心原因是Blob版本管理属于存储账户级别的配置,并非Blob服务层面的属性,因此无法通过BlobServiceClient的方法获取,需要使用Azure存储管理SDK(azure-mgmt-storage)来查询。

具体解决方案:

  1. 先安装所需的管理SDK包:
pip install azure-mgmt-storage azure-identity
  1. 使用以下代码获取存储账户的版本启用状态:
from azure.identity import DefaultAzureCredential
from azure.mgmt.storage import StorageManagementClient

def get_blob_versioning_status():
    # 替换为你的实际信息
    subscription_id = "<你的订阅ID>"
    resource_group_name = "rg-exercise1"
    storage_account_name = "sa36730"

    # 通过Azure AD凭据认证(本地开发可先通过Azure CLI登录获取默认凭据)
    credential = DefaultAzureCredential()
    storage_client = StorageManagementClient(credential, subscription_id)

    # 获取存储账户的Blob服务属性(包含版本管理配置)
    blob_service_config = storage_client.blob_services.get_service_properties(
        resource_group_name, storage_account_name
    )

    # 提取版本启用状态
    is_versioning_enabled = blob_service_config.is_versioning_enabled
    print(f"Blob版本管理是否启用: {is_versioning_enabled}")

get_blob_versioning_status()

补充说明:

你之前调用的BlobServiceClient.get_service_properties()返回的是Blob服务的基础配置(如日志规则、CORS策略、删除保留策略等),并不包含账户级别的版本管理设置,因此无法获取到目标字段。

内容的提问来源于stack exchange,提问作者abhinav singh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.01 20:15:27