中国站
帮助中心 > 网络与加速 > > > Python SDK使用说明

Python SDK使用说明

本文介绍Python SDK使用说明。请您按照以下步骤操作。

环境准备

Python 2.7+

SDK安装

1.安装阿里云核心SDK

  1. sudo pip install aliyun-python-sdk-core
  1. 安装阿里云视频直播SDK
  1. sudo pip install aliyun-python-sdk-live

SDK更新

  1. 更新阿里云核心SDK
  1. sudo pip install aliyun-python-sdk-core --upgrade
  1. 更新阿里云视频直播SDK
  1. sudo pip install aliyun-python-sdk-live --upgrade

SDK移除

  1. sudo pip uninstall aliyun-python-sdk-core
  2. sudo pip uninstall aliyun-python-sdk-live

接口说明

DescribeLiveStreamsFrameRateAndBitRateData接口为例。

以下是SDK中的DescribeLiveStreamsFrameRateAndBitRateDataRequest.py

  1. # Licensed to the Apache Software Foundation (ASF) under one
  2. # or more contributor license agreements. See the NOTICE file
  3. # distributed with this work for additional information
  4. # regarding copyright ownership. The ASF licenses this file
  5. # to you under the Apache License, Version 2.0 (the
  6. # "License"); you may not use this file except in compliance
  7. # with the License. You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. #
  12. #
  13. # Unless required by applicable law or agreed to in writing,
  14. # software distributed under the License is distributed on an
  15. # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. # KIND, either express or implied. See the License for the
  17. # specific language governing permissions and limitations
  18. # under the License.
  19. from aliyunsdkcore.request import RpcRequest
  20. class DescribeLiveStreamsFrameRateAndBitRateDataRequest(RpcRequest):
  21. def __init__(self):
  22. RpcRequest.__init__(self, 'live', '2016-11-01', 'DescribeLiveStreamsFrameRateAndBitRateData','live')
  23. def get_SecurityToken(self):
  24. return self.get_query_params().get('SecurityToken')
  25. def set_SecurityToken(self,SecurityToken):
  26. self.add_query_param('SecurityToken',SecurityToken)
  27. def get_OwnerId(self):
  28. return self.get_query_params().get('OwnerId')
  29. def set_OwnerId(self,OwnerId):
  30. self.add_query_param('OwnerId',OwnerId)
  31. def get_DomainName(self):
  32. return self.get_query_params().get('DomainName')
  33. def set_DomainName(self,DomainName):
  34. self.add_query_param('DomainName',DomainName)
  35. def get_AppName(self):
  36. return self.get_query_params().get('AppName')
  37. def set_AppName(self,AppName):
  38. self.add_query_param('AppName',AppName)
  39. def get_StreamName(self):
  40. return self.get_query_params().get('StreamName')
  41. def set_StreamName(self,StreamName):
  42. self.add_query_param('StreamName',StreamName)
  43. def get_StartTime(self):
  44. return self.get_query_params().get('StartTime')
  45. def set_StartTime(self,StartTime):
  46. self.add_query_param('StartTime',StartTime)
  47. def get_EndTime(self):
  48. return self.get_query_params().get('EndTime')
  49. def set_EndTime(self,EndTime):
  50. self.add_query_param('EndTime',EndTime)

该文件中对于DescribeLiveStreamsFrameRateAndBitRateDataRequest这个类,有若干组一一对应的get_Xset_X方法,分别用于设定该 API 请求的参数,具体每一个请求参数对应的意义,您可以在阿里云官网的直播 API 文档中找到。

SDK使用

v20161101版本为例。

以调用DescribeLiveStreamsFrameRateAndBitRateDataRequest接口为例。

  1. # 引入aliyunsdkcore包
  2. from aliyunsdkcore import client
  3. # 引入aliyunsdklie包
  4. from aliyunsdklive.request.v20161101 import DescribeLiveStreamsFrameRateAndBitRateDataRequest
  5. # 初始化client
  6. # AK和Secrect需要自己提供(可以在阿里云控制台中找到)
  7. # 以访问cn-hangzhou region为例
  8. clt = client.AcsClient(AK, Secret, 'cn-hangzhou')
  9. # 构造需发起的API请求调用
  10. request = DescribeLiveStreamsFrameRateAndBitRateDataRequest.DescribeLiveStreamsFrameRateAndBitRateDataRequest()
  11. request.set_DomainName('qt1.alivecdn.com')
  12. request.set_AppName('caster')
  13. request.set_StreamName('cc8d5e157f5d4146afd091e246efd1f6')
  14. # 发起请求
  15. result = clt.do_action_with_exception(request)
  16. # 请求结果
  17. # result为请求结果的ResponseBody字符串
  18. print result
  19. # 如果您需要进一步对result进行处理,可以根据每个接口的返回格式,进行格式化处理并进一步分析或使用
  20. # 对于DescribeLiveStreamsFrameRateAndBitRateDataRequest来说,它返回一个json格式的数据,我们可以用json包来处理这些response
  21. import json
  22. x = json.loads(result)
  23. print x['RequestId']
  24. print x['FrameRateAndBitRateInfos']