This topic describes how to use the Python SDK to set person information.
Usage notes
The purpose of setting person information is to add remarks to the corresponding person. Setting person information is an optional step. After you setting information about a person, the information is included in the returned results of custom retrieval. For more information about the parameters, see API operation for setting person information.
You need to use the endpoints of the Content Moderation API to call this SDK. For more information about the endpoints, see Endpoints.
Prerequisites
Python dependencies are installed. For more information, see Installation.
NoteYou must use the required Python version described in the Installation topic to install the dependencies. Otherwise, subsequent operation calls fail.
The Extension.Uploader utility class is downloaded and imported into your project.
Sample code for setting person information
# coding=utf-8
# Set person information.
from aliyunsdkcore import client
from aliyunsdkcore.profile import region_provider
from aliyunsdkgreen.request.v20180509 import SetPersonRequest
import json
# Note: We recommend that you reuse the instantiated client as much as possible. This improves moderation performance and avoids repeated client connections.
# Common ways to obtain environment variables:
# Obtain the AccessKey ID of your RAM user: os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID']
# Obtain the AccessKey secret of your RAM user: os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
clt = client.AcsClient("We recommend that you obtain the AccessKey ID of your RAM user from environment variables", "We recommend that you obtain the AccessKey secret of your RAM user from environment variables", "cn-shanghai")
region_provider.modify_point('Green', 'cn-shanghai', 'green.cn-shanghai.aliyuncs.com')
request = SetPersonRequest.SetPersonRequest()
request.set_accept_format('JSON')
request.set_content(
bytearray(json.dumps({"personId": "python_personId_test_1", "name": "Test", "note": "Remarks"}), "utf-8"))
response = clt.do_action_with_exception(request)
print response
result = json.loads(response)
if 200 == result["code"]:
resultObject = result["data"]
if (200 == resultObject["code"]):
# The status code 200 indicates that person information is set.
personId = resultObject["personId"]
print personId