# UniversalClient 类

## 简要

代表通用产品客户端的类。通过利用该类，您可以以同步或异步面向对象的编程方式快速访问 Tencent Cloud API 并获得结果，而无需关注实现细节。

通常情况下，通用产品客户端用作 Tencent Cloud SDK for Python 暂未提供抽象产品客户端的 Tencent Cloud 产品，其具有直接访问 Tencent Cloud API 的能力。

```python
class UniversalClient(BaseClient)
```

继承：`tencent.cloud.core.client.BaseClient` 类

{% hint style="info" %}
请注意，通用产品客户端仅适用于支持 TC3-HMAC-SHA256 签名方法的 Tencent Cloud API v3 版本，较旧的签名方法或 Tencent Cloud API 版本暂不支持。
{% endhint %}

**Tips**: 从 Tencent Cloud SDK for Python 0.1.4 版本起，所有产品客户端类型应该从 `UniversalClient` 继承，而不是从 `BaseClient` 继承。

## 构造

该类仅支持构造类实例后使用，其构造实例方法签名如下：

```python
def __init__(self,
    product_id: str,
    access_credentials: credentials.Credentials = None,
    access_proiexs: proxies.Proxies = None
)
```

构造实例方法参数和参数描述如下：

| 参数                  | 类型                                                                                                          | 必选 | 描述                                                      |
| ------------------- | ----------------------------------------------------------------------------------------------------------- | -- | ------------------------------------------------------- |
| product\_id         | str                                                                                                         | 是  | <p>Tencent Cloud 产品唯一标识符。</p><p>例如：<code>cvm</code></p> |
| access\_credentials | Credentials                                                                                                 | 否  | 访问凭据类实例。如果该参数被忽略或设置为 `None`，默认设置为环境凭据或文件凭据。             |
| access\_proiexs     | [Proxies](https://smallso.gitbook.io/tencent-cloud-sdk/python-docs/other-products/class-and-method/proxies) | 否  | 代理服务器配置类实例。如果该参数被忽略或设置为 `None`，默认不使用任何代理服务器。            |

### 兼容性

请注意，对于 Tencent Cloud SDK for Python 0.1.3 或更低版本，部分参数名称为：

| 文档中的参数名             | 旧的参数名                | 类型一致 | 行为一致 |
| ------------------- | -------------------- | ---- | ---- |
| access\_credentials | credentials\_context | 是    | 是    |
| access\_proxies     | proxies\_context     | 是    | 是    |

值得注意的是，旧版本除参数名称不同外，与新版本中的参数数据类型和行为是一致的。

## 属性

该类型的实例包含可被公开访问的属性有：

| 属性             | 类型           | 只读 | 描述                                                                                                                                                                                                                                                                                                    |
| -------------- | ------------ | -- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| error\_manager | ErrorManager | 是  | 当前通用客户端实例的错误管理器实例。借助错误管理器，您可以自定义对感兴趣地错误的处理方式。                                                                                                                                                                                                                                                         |
| credentials    | Credentials  | 是  | 当前通用客户端实例所绑定的访问凭据实例。                                                                                                                                                                                                                                                                                  |
| proxies        | Proxies      | 是  | <p>当前通用客户端实例所绑定的一个或多个代理服务器配置实例。如果需要修改代理服务器配置，请使用 <a href="https://smallso.gitbook.io/tencent-cloud-sdk/python-docs/other-products/class-and-method/universal-client/set-access-proxies"><code>set\_access\_proxies</code></a> 方法。</p><p></p><p>请注意，如果当前通用客户端未设置代理服务器配置，该属性默认值为 <code>None</code>。</p> |

### 兼容性

该类型部分可被公开访问的属性可能需要最新的 Tencent Cloud SDK for Python 版本：

| 属性             | 软件包                    | 版本要求     |
| -------------- | ---------------------- | -------- |
| error\_manager | tencent-cloud-sdk-core | >= 0.1.2 |
| credentials    | tencent-cloud-sdk-core | >= 0.1.2 |
| proxies        | tencent-cloud-sdk-core | >= 0.1.3 |

## 示例

在下文中我们将向您演示如何构造一个通用产品客户端类实例：

```python
from tencent.cloud.core import client
from tencent.cloud.auth import credentials

# Please replace with your access credentials

access_credentials = credentials.Credentials(
    secret_id = 'AKIDF3sMOAU1pOgkmrKHchX6TZQ1Mo1C5qa7',
    secret_key = 'b4JL8fwxkIgsKMXGi39yYt0ECxZw4wZf'
)

virtual_machine_client: client.UniversalClient = client.UniversalClient(
    product_id = 'cvm',
    access_credentials = access_credentials
)

action_result: dict = virtual_machine_client.action(
    region_id = 'ap-shanghai',
    action_id = 'DescribeZones',
    action_version = '2017-03-12'
)

for zone_info in action_result['ZoneSet']:
    print(zone_info['Zone'])
```

## 适用于

#### Tencent Cloud SDK for Python

产品软件包：tencent-cloud-sdk-serverless-functions >= 0.1.3


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://smallso.gitbook.io/tencent-cloud-sdk/python-docs/other-products/class-and-method/universal-client.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
