本文介紹Python SDK的安裝及使用說明。
SDK安裝
pip install alibabacloud_vs20181212==2.0.0
SDK使用
以下這個代碼示例展示了調用阿里云Python SDK的3個主要步驟:
創建Config實例。在創建Config實例時,您需要獲取Endpoint、AccessKey ID和AccessKey Secret。
創建API請求并設置參數。
發起請求并處理應答或異常。
# -*- 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 方式,更多鑒權訪問方式請參見:http://bestwisewords.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:])
文檔內容是否對您有幫助?