本篇文档为您介绍了如何使用账号AccessKey以及STS的示例代码进行Python SDK初始化。

前提条件

初始化

点播服务的接入区域请参见接入区域和标识,例如:接入区域在上海,请使用cn-shanghai

  1. 填入账号AccessKey信息,进行初始化。示例如下:
    # -*- coding: UTF-8 -*-
    import json
    import traceback
    from aliyunsdkcore.client import AcsClient
    
    def init_vod_client(accessKeyId, accessKeySecret):
        regionId = 'cn-shanghai'   # 点播服务接入区域
        connectTimeout = 3         # 连接超时,单位为秒
        return AcsClient(accessKeyId, accessKeySecret, regionId, auto_retry=True, max_retry_time=3, timeout=connectTimeout)
  2. 填入STS信息,进行初始化。示例如下:
    # -*- coding: UTF-8 -*-
    import json
    import traceback
    from aliyunsdkcore.client import AcsClient
    from aliyunsdkcore.auth.credentials import StsTokenCredential
    
    def init_vod_client(accessKeyId, accessKeySecret, securityToken):
        regionId = 'cn-shanghai'   # 点播服务接入区域
        connectTimeout = 3         # 连接超时,单位为秒
        credential = StsTokenCredential(accessKeyId, accessKeySecret, securityToken)
        return AcsClient(region_id=regionId, auto_retry=True, max_retry_time=3, timeout=connectTimeout, credential=credential)