Coder Social home page Coder Social logo

tencentcloud-sdk-python's Introduction

简介

欢迎使用腾讯云开发者工具套件(SDK)3.0,SDK3.0是云 API3.0 平台的配套工具。目前已经支持cvm、vpc、cbs等产品,后续所有的云服务产品都会接入进来。新版SDK实现了统一化,具有各个语言版本的SDK使用方法相同,接口调用方式相同,统一的错误码和返回包格式这些优点。 为方便 Python 开发者调试和接入腾讯云产品 API,这里向您介绍适用于 Python 的腾讯云开发工具包,并提供首次使用开发工具包的简单示例。让您快速获取腾讯云 Python SDK 并开始调用。

依赖环境

  1. 依赖环境:Python 2.7 到 3.6 版本。
  2. 从 腾讯云控制台 开通相应产品。
  3. 获取 SecretID、SecretKey 以及调用地址(endpoint),endpoint 一般形式为*.tencentcloudapi.com,如CVM 的调用地址为 cvm.tencentcloudapi.com,具体参考各产品说明。

获取安装

安装 Python SDK 前,先获取安全凭证。在第一次使用云 API 之前,用户首先需要在腾讯云控制台上申请安全凭证,安全凭证包括 SecretID 和 SecretKey, SecretID 是用于标识 API 调用者的身份,SecretKey 是用于加密签名字符串和服务器端验证签名字符串的密钥。SecretKey 必须严格保管,避免泄露。

通过 Pip 安装(推荐)

您可以通过 pip 安装方式将腾讯云 API Python SDK 安装到您的项目中,如果您的项目环境尚未安装 pip,请详细参见 pip官网 安装。

通过pip方式安装请在命令行中执行以下命令:

pip install tencentcloud-sdk-python

请注意,如果同时有 python2 和 python3 环境, python3 环境需要使用 pip3 命令安装。

通过源码包安装

前往 Github 代码托管地址 下载最新代码,解压后

$ cd tencentcloud-sdk-python
$ python setup.py install

示例

以查询可用区接口为例:

# -*- coding: utf-8 -*-
from tencentcloud.common import credential
from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
# 导入对应产品模块的client models。
from tencentcloud.cvm.v20170312 import cvm_client, models
try:
    # 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey
    cred = credential.Credential("secretId", "secretKey")

    # 实例化要请求产品(以cvm为例)的client对象
    client = cvm_client.CvmClient(cred, "ap-shanghai")

    # 实例化一个请求对象
    req = models.DescribeZonesRequest()

    # 通过client对象调用想要访问的接口,需要传入请求对象
    resp = client.DescribeZones(req)
    # 输出json格式的字符串回包
    print(resp.to_json_string())

except TencentCloudSDKException as err:
    print(err)

您可以在github中examples目录下找到更详细的示例。

相关配置

代理

如果是有代理的环境下,需要设置系统环境变量 https_proxy ,否则可能无法正常调用,抛出连接超时的异常。

证书问题

在 Mac 操作系统安装 Python 3.6 或以上版本时,可能会遇到证书错误:Error: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1056).。这是因为在 Mac 操作系统下,Python 不再使用系统默认的证书,且本身也不提供证书。在进行 HTTPS 请求时,需要使用 certifi 库提供的证书,但 SDK 不支持指定,所以只能使用 sudo "/Applications/Python 3.6/Install Certificates.command" 命令安装证书才能解决此问题。

虽然 Python 2 版本不应该有同样的问题,但是在个别用户环境上确实也观察到有类似的情况,也一样可以通过 sudo /Applications/Python 2.7/Install Certificates.command 解决。

tencentcloud-sdk-python's People

Contributors

tencentcloudapi avatar zqfan avatar hitxingkong avatar fxh123 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.