Set person information

更新时间:
复制 MD 格式

Use the Content Moderation Python SDK to attach a name and remarks to a person in your custom library. After you set person information, the name and note values are returned alongside the person ID in custom retrieval results, letting you identify and filter results without a separate lookup.

Setting person information is optional.

Prerequisites

Before you begin, ensure that you have:

Important

Use the Python version specified in the Installation guide. Using a different version causes subsequent API calls to fail.

Set person information

The following example calls SetPersonRequest to attach a name and note to a person.

# coding=utf-8
import os
import json
from aliyunsdkcore import client
from aliyunsdkcore.profile import region_provider
from aliyunsdkgreen.request.v20180509 import SetPersonRequest

# Reuse the client instance across requests to improve performance
# and avoid repeated connection overhead.
# Get credentials from environment variables — do not hardcode them.
clt = client.AcsClient(
    os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_ID"),      # AccessKey ID
    os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_SECRET"),  # AccessKey secret
    "cn-shanghai"
)
region_provider.modify_point("Green", "cn-shanghai", "green.cn-shanghai.aliyuncs.com")

request = SetPersonRequest.SetPersonRequest()
request.set_accept_format("JSON")

# Request body: personId identifies the target person;
# name and note are stored and returned in custom retrieval results.
request.set_content(
    bytearray(
        json.dumps({
            "personId": "<your-person-id>",
            "name": "<display-name>",
            "note": "<remarks>"
        }),
        "utf-8"
    )
)

response = clt.do_action_with_exception(request)
result = json.loads(response)

if result["code"] == 200 and result["data"]["code"] == 200:
    # Person information set successfully.
    person_id = result["data"]["personId"]
    print(person_id)

Request parameters

ParameterTypeDescriptionExample
personIdStringThe ID of the person to update.python_personId_test_1
nameStringThe display name attached to the person. Returned as name in custom retrieval results.Test
noteStringFree-text remarks for this person. Returned as note in custom retrieval results.Remarks

Check the response

A successful call returns HTTP status code 200 at two levels: the outer code field and data.code. On success, data.personId contains the ID of the updated person.

If either code is not 200, the operation did not complete. Refer to API operation for setting person information for error codes.

What's next