Python SDK包含阿里云Python SDK公共部分和产品部分,公共部分SDK为aliyun-python-sdk-core,产品部分SDK为aliyun-python-sdk-cr。每个接口的详细使用方法请参考API概览

安装

安装公共部分Python SDK,请参见快速开始。然后通过以下命令安装产品部分Python SDK

pip install aliyun-python-sdk-cr

API调用示例

#!/usr/bin/env python
# coding=utf-8

from aliyunsdkcore.acs_exception.exceptions import ClientException
from aliyunsdkcore.acs_exception.exceptions import ServerException
from aliyunsdkcore.client import AcsClient

from aliyunsdkcr.request.v20160607 import GetImageLayerRequest

# 示例执行异常时建议升级aliyun-python-sdk-core到最新版本

# 设置Client
apiClient = AcsClient('AccessKeyId', 'AccessKeySecret', 'cn-hangzhou')

# 构造请求
request = GetImageLayerRequest.GetImageLayerRequest()

# 设置参数
request.set_RepoNamespace("repoNamespaceName")
request.set_RepoName("repoName")
request.set_Tag("tag")

# 根据文档获取资源所在区域对应的RegionId
# 请求地址格式为cr.{regionId}.aliyuncs.com
request.set_endpoint("cr.cn-hangzhou.aliyuncs.com")

# 发起请求
try:
    response = apiClient.do_action_with_exception(request)
    print(response)
except ServerException as e:
    print(e)
except ClientException as e:
    print(e)