Use the Content Moderation Python SDK to retrieve information about a registered person by their personId.
Prerequisites
Before you begin, ensure that you have:
Installed the Python SDK dependencies. For the required Python version and installation steps, see Installation.
Note Note: You must use the Python version specified in the Installation topic. Using an unsupported version causes API calls to fail.Downloaded and imported the Extension.Uploader utility class into your project.
Usage notes
For the full parameter reference, see API operation for querying person information.
Use a Content Moderation API endpoint when initializing the client. For available endpoints, see Endpoints.
Reuse the client instance across calls to improve performance and avoid repeated connection overhead.
Query person information
Placeholders
Replace the following placeholders in the sample code before running it.
| Placeholder | Description | Example |
|---|---|---|
<your-access-key-id> | AccessKey ID of your RAM user | LTAI5tXxx |
<your-access-key-secret> | AccessKey secret of your RAM user | xXxXxXx |
<your-person-id> | The personId of the person to query | python_personId_test_1 |
Sample code
# coding=utf-8
import json
import os
from aliyunsdkcore import client
from aliyunsdkcore.profile import region_provider
from aliyunsdkgreen.request.v20180509 import GetPersonRequest
# Initialize the client. Reuse this instance across calls.
access_key_id = os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_ID")
access_key_secret = os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
clt = client.AcsClient(access_key_id, access_key_secret, "cn-shanghai")
region_provider.modify_point("Green", "cn-shanghai", "green.cn-shanghai.aliyuncs.com")
# Build the request
request = GetPersonRequest.GetPersonRequest()
request.set_accept_format("JSON")
request.set_content(json.dumps({"personId": "<your-person-id>"}))
# Send the request and parse the response
response = clt.do_action_with_exception(request)
result = json.loads(response)
if result["code"] == 200:
data = result["data"]
if data["code"] == 200:
# Person information retrieved successfully
person_id = data["personId"]
print(person_id)Response structure
A successful response returns two nested status codes.
| Field | Type | Description |
|---|---|---|
result["code"] | Integer | Outer status code. 200 indicates the request was accepted. |
result["data"] | Object | Contains the person information payload. |
result["data"]["code"] | Integer | Inner status code. 200 indicates person information was retrieved successfully. |
result["data"]["personId"] | String | The personId of the retrieved person. |
What's next
To register a new person, see the API operation for registering person information.
To delete a person, see the API operation for deleting person information.