Help Center/
Content Moderation/
SDK Reference/
Using the Python SDK/
SDK Calling Example/
Moderation (Image)/
Image Moderation (Asynchronous Batch) (V2)/
Submitting a Task
Updated on 2023-07-17 GMT+08:00
Submitting a Task
- This section describes how to use the Image Moderation SDK by AK/SK authentication.
Replace the AK/SK in the sample code with the actual AK/SK. You can set urls in TaskSumbitReq to configure the URLs of the images to be reviewed, and then execute the code.
# coding: utf-8 from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkmoderation.v2.region.moderation_region import ModerationRegion from huaweicloudsdkmoderation.v2 import * from huaweicloudsdkmoderation.v2 import ModerationClient,RunTaskSumbitRequest,TaskSumbitReq if __name__ == "__main__": //Enter your AK/SK. ak = "<YOUR AK>" sk = "<YOUR SK>" credentials = BasicCredentials(ak, sk) client = ModerationClient.new_builder() \ .with_credentials(credentials) \ .with_region(ModerationRegion.value_of("xxx")) \ //Replace xxx with the region where the service is located. .build() try: request = RunTaskSumbitRequest() listTaskSumbitReqCategoriesbody = [ "porn", ] listTaskSumbitReqUrlsbody = [ "https://XXX.jpg" //Replace it with an image URL that can be accessed from the Internet. ] request.body = TaskSumbitReq( categories=listTaskSumbitReqCategoriesbody, urls=listTaskSumbitReqUrlsbody ) response = client.run_task_sumbit(request) print(response.status_code) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg)
- If 200 is displayed on the console, the code is successfully executed. The result of submitting the Image Moderation (Asynchronous Batch) task is displayed on the console.
200 {'result': {'job_id': 'xxx'}} Process finished with exit code 0
Parent topic: Image Moderation (Asynchronous Batch) (V2)
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
The system is busy. Please try again later.
For any further questions, feel free to contact us through the chatbot.
Chatbot