Python SDK 示例

安装 SDK

Python SDK 使用说明:https://help.aliyun.com/document_detail/53090.html

调用 Codeup API

以 CreateRepository 为例:

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

from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.request import CommonRequest
client = AcsClient('<accessKeyId>', '<accessSecret>', 'cn-hangzhou')

request = CommonRequest()
request.set_accept_format('json')
request.set_method('POST')
request.set_protocol_type('https') # https | http
request.set_domain('codeup.cn-hangzhou.aliyuncs.com')
request.set_version('2020-04-14')

request.add_query_param('RegionId', "cn-hangzhou")
request.add_query_param('OrganizationId', "<OrganizationId>")
request.add_header('Content-Type', 'application/json')
request.set_uri_pattern('/api/v3/projects')
body = '''{
    "name": "<RepoName>",
    "path": "<RepoPath>",
    "visibility_level": 10,
    "namespace_id": 123
}'''
request.set_content(body.encode('utf-8'))

response = client.do_action_with_exception(request)

# python2:  print(response) 
print(str(response, encoding = 'utf-8'))