Python SDK

本文介绍Python SDK的安装及使用说明。

SDK安装

  1. 安装Alibaba Cloud VS SDK for Python

pip install alibabacloud_vs20181212==2.0.0
		

SDK使用

以下这个代码示例展示了调用阿里云Python SDK的3个主要步骤:

  1. 创建Config实例。在创建Config实例时,您需要获取Endpoint、AccessKey ID和AccessKey Secret。

  2. 创建API请求并设置参数。

  3. 发起请求并处理应答或异常。

# -*- coding: utf-8 -*-
# This file is auto-generated, don't edit it. Thanks.
import os
import sys

from typing import List

from alibabacloud_vs20181212.client import Client as vs20181212Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_vs20181212 import models as vs_20181212_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient


class Sample:
    def __init__(self):
        pass

    @staticmethod
    def create_client() -> vs20181212Client:
        """
        使用AK&SK初始化账号Client
        @return: Client
        @throws Exception
        """
        # 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。
        # 建议使用更安全的 STS 方式,更多鉴权访问方式请参见:https://help.aliyun.com/document_detail/378659.html。
        config = open_api_models.Config(
            # 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。,
            access_key_id=os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'],
            # 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。,
            access_key_secret=os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
        )
        # Endpoint 请参考 https://api.aliyun.com/product/vs
        config.endpoint = f'vs.cn-beijing.aliyuncs.com'
        return vs20181212Client(config)

    @staticmethod
    def main(
        args: List[str],
    ) -> None:
        client = Sample.create_client()
        add_vs_pull_stream_info_config_request = vs_20181212_models.AddVsPullStreamInfoConfigRequest(
            domain_name='your_value',
            app_name='your_value'
        )
        try:
            # 复制代码运行请自行打印 API 的返回值
            client.add_vs_pull_stream_info_config_with_options(add_vs_pull_stream_info_config_request, util_models.RuntimeOptions())
        except Exception as error:
            # 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
            # 错误 message
            print(error.message)
            # 诊断地址
            print(error.data.get("Recommend"))
            UtilClient.assert_as_string(error.message)

    @staticmethod
    async def main_async(
        args: List[str],
    ) -> None:
        client = Sample.create_client()
        add_vs_pull_stream_info_config_request = vs_20181212_models.AddVsPullStreamInfoConfigRequest(
            domain_name='your_value',
            app_name='your_value'
        )
        try:
            # 复制代码运行请自行打印 API 的返回值
            await client.add_vs_pull_stream_info_config_with_options_async(add_vs_pull_stream_info_config_request, util_models.RuntimeOptions())
        except Exception as error:
            # 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
            # 错误 message
            print(error.message)
            # 诊断地址
            print(error.data.get("Recommend"))
            UtilClient.assert_as_string(error.message)


if __name__ == '__main__':
    Sample.main(sys.argv[1:])