TencentCloud / tencentcloud-sdk-python

Tencent Cloud API 3.0 SDK for Python
Apache License 2.0
613 stars 251 forks source link

add proxy settings #56

Closed zqfan closed 4 years ago

V-know commented 4 years ago

I need this badly as well

V-know commented 4 years ago

I need this badly as well

proxy with authentication

devmiek commented 4 years ago

The current community version of the Tencent Cloud SDK for Python has better support for proxy server configuration.

Take the serverless cloud function product as an example:

Import Module

First we need to import the Tencent Cloud SDK for Python related namespaces and modules:

from tencent.cloud.core import proxies
from tencent.cloud.serverless import functions

Product Client

Next we need to instantiate a serverless cloud function product client instance:

client = functions.Client(
    access_proxies = proxies.Proxies(
        proxy_name = 'default',
        proxy_type = proxies.ProxyType.Http,
        proxy_endpoint = '127.0.0.1:1080',
        proxy_auth = {
            'username': 'root',
            'password': 'root'
        }
    )
)

Of course, there is another way:

client = functions.fetch_client()  # This is related to the current hyper-thread.
client.set_access_proxies(...)  # The parameters are consistent with access_proxies.

Call Function

Finally we call a serverless cloud function and get the native return value:

text: str = client.easy_invoke('ap-shanghai', 'default', 'hello')
print('return value: ' + text)

Data Type Proxies also supports managing multiple proxy server configurations, which can be set by accessing the proxies properties of the client instance.

The Tencent Cloud SDK for Python Community Edition is now available through GitHub and PyPI, see the detailed online documentation for more details.

GitHub repository: https://github.com/nobody-night/tencent-cloud-sdk-python Online documentation: https://smallso.gitbook.io/tencent-cloud-sdk/

Instantnoodles-madman commented 4 years ago

我配置代理时,提示我 missing environment variable <'TENCENTCLOUD_SECRETID'> 请问是什么错误

devmiek commented 4 years ago

我配置代理时,提示我 missing environment variable <'TENCENTCLOUD_SECRETID'> 请问是什么错误

@Instantnoodles-madman Hi, Instantnoodles-madman! 该错误指示当前运行环境缺少环境变量 TENCENTCLOUD_SECRETID,该环境变量用于存储 Tencent Cloud API 访问凭据的 Secret ID 值。我想这可能与您使用 Tencent Cloud SDK for Python 的方式有关,如果没有指定访问凭据,默认 Tencent Cloud SDK for Python 将采用一种被称之为“环境凭据”的访问凭据类型来访问 Tencent Cloud API,也即通过获取运行环境中预设的环境变量作为访问凭据。目前支持的访问凭据类型有:

Tencent Cloud SDK for Python 简体中文在线文档的入门篇中会向开发者介绍如何创建并获取适用于您 Tencent Cloud 账户的凭据,然后如何将其用于 Tencent Cloud SDK for Python;最佳实践篇中也会向开发者介绍如何选择并使用适合的访问凭据类型。请您参阅:

相信您通过阅读 Tencent Cloud SDK for Python 在线文档能很快掌握其使用方法。如果您有其他关于 Tencent Cloud SDK for Python 等非该 Issue 主题的问题,请考虑转到 https://github.com/nobody-night/tencent-cloud-sdk-python/issues 跟踪器打开一个新 Issue。

zqfan commented 4 years ago

fixed by https://github.com/TencentCloud/tencentcloud-sdk-python/commit/db68d5e0f2d590dc64c5c7523cd7323d3a1bb8ff