# action\_for\_product 方法

## 简要

调用给定 Tencent Cloud 产品的指定 Tencent Cloud API 并获得结果。

与方法 `action` 或 `action_async` 不同，该方法提供对多个 Tencent Cloud 产品的 Tencent Cloud API 混合调用的能力。例如我们可以在适用于 Cloud Virtual Machine 产品的通用产品客户端中调用适用于 Serverless Cloud Function 产品的 Tencent Cloud API，而不局限于当前客户端所绑定的 Tencent Cloud 产品 ID 的限制，我们将该高级特性称之为对 Tencent Cloud 产品的混合调用。

```python
def action_for_product(self,
    product_id: str,
    region_id: str,
    action_id: str,
    action_parameters: dict,
    action_version: str,
    action_endpoint: str = None
) -> dict
```

## 参数

该方法具有以下参数，其参数、参数类型和参数描述如下：

| 参数                 | 类型   | 必选 | 描述                                                                                                    |
| ------------------ | ---- | -- | ----------------------------------------------------------------------------------------------------- |
| product\_id        | str  | 是  | <p>Tencent Cloud 产品唯一标识符。</p><p>例如：<code>cvm</code></p>                                               |
| region\_id         | str  | 是  | <p>数据中心园区的可用区唯一标识符。</p><p>例如：<code>ap-shanghai-1</code></p>                                           |
| action\_id         | str  | 是  | <p>Tencent Cloud API 唯一标识符。</p><p>例如：<code>DescribeZones</code></p>                                   |
| action\_parameters | dict | 否  | <p>包含 Tencent Cloud API 参数和参数值的字典实例。</p><p>对于没有参数的 Tencent Cloud API，该参数应该被设置为 <code>None</code>。</p> |
| action\_version    | str  | 是  | <p>Tencent Cloud API 版本名称。</p><p>例如：<code>2017-03-12</code></p>                                       |
| action\_endpoint   | str  | 否  | <p>Tencent Cloud API 端点主机名。</p><p>例如：<code>cvm.tencentcloudapi.com</code></p>                         |

## 返回值

该方法返回包含给定 Tencent Cloud API 响应结构的字典实例。

## 异常

该方法可能会主动引发以下异常类型：

#### ValueError

参数值或类型不符合预期。

#### RequestError

Tencent Cloud SDK for Python 请求给定 Tencent Cloud API 时出错，这可能是由于网络原因所引起的。

#### ResponseError

Tencent Cloud SDK for Python 解析给定 Tencent Cloud API 响应内容结构时出错，这可能是由于响应内容不符合预期所引起的（例如使用非 Tencent Cloud API v3 版本）。

#### ActionError

给定 Tencent Cloud API 遇到错误，这可能是由于访问凭据无效、参数值或类型不符合预期等引起。

## 示例

接下来我们将通过一段 Python 代码向您演示如何使用该方法：

```python
action_result: dict = virtual_machine_client.action_for_product(
    product_id = 'scf',
    region_id = 'ap-shanghai',
    action_id = 'Invoke',
    action_parameters = {
        'Namespace': 'default',
        'FunctionName': 'hello'
    },
    action_version = '2018-04-16'
)
```

您或许已经注意到，我们已在适用于 Cloud Virtual Machine 产品的通用产品客户端中调用 Serverless Cloud Function 产品提供的 Tencent Cloud API。

## 适用于

#### Tencent Cloud SDK for Python

基础软件包：tencent-cloud-sdk-core >= 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/action-for-product.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.
