最近更新时间:2025-06-18 20:51:54
1. Python SDK从V1.4.0版本开始支持项目id过滤参数project_ids
。
2. Python SDK从V1.13.0版本开始支持根据Region、前缀、访问类型、存储类型进行过滤。
以下代码用于列出您全部存储空间信息:
from ks3.connection import Connection
# 金山云主账号AccessKey拥有所有API的访问权限,风险很高。
# 强烈建议您创建并使用子账号账号进行API访问或日常运维,请登录https://uc.console.ksyun.com/pro/iam/#/user/list创建子账号。
# 通过指定host(Endpoint),您可以在指定的地域创建新的存储空间。
c = Connection('<YOUR_ACCESS_KEY>', '<YOUR_SECRET_KEY>', host='<YOUR_REGION_ENDPOINT>')
# 获取客户所有的Bucket信息。
# 示例1:projectIds 为项目id,多个项目用“,”间隔
try:
buckets = c.get_all_buckets(project_ids="<YOUR_PROJECT_IDS>")
# 打印出bucket的信息。
for b in buckets:
print(b.name)
print(b.region)
print(b.VisitType)
print(b.type)
except Exception as e:
print('request_id: %s' % e.request_id)
print(e)
# SDK 1.13.0版本之后支持该功能
# 示例2:根据Region、前缀、访问类型、存储类型过滤Bucket
# 以 region:BEIJING,prefix:abc,visit_type:NORMAL,storage_type: NORMAL 为例
try:
buckets = c.get_all_buckets(region='BEIJING', prefix='abc', visit_type='NORMAL', storage_type='NORMAL')
# 打印出Bucket的信息。
for b in buckets:
print(b.name)
print(b.region)
print(b.VisitType)
print(b.type)
except Exception as e:
print('request_id: %s' % e.request_id)
print(e)
纯净模式