Query a list of similar image libraries
This topic describes how to use the Python SDK to perform a paged query of similar image libraries and their element information.
Feature description
You can call this operation to perform a paged query of all similar image libraries and their element information. For more information about the parameters, see the Query a list of similar image libraries API reference.
You must use the Content Moderation endpoint to call the service using the SDK. For more information about API 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.
Query a list of similar image libraries
# coding=utf-8
# The following example uses Python 3.x. The procedure for Python 2.x is similar.
import json
from aliyunsdkcore import client
from aliyunsdkcore.profile import region_provider
from aliyunsdkgreen.request.v20180509 import ListSimilarityLibrariesRequest
# Note: To improve detection performance, reuse the instantiated client. This avoids repeated connection establishment.
# Common methods to obtain environment variables:
# Obtain the AccessKey ID of a RAM user: os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID']
# Obtain the AccessKey secret of a RAM user: os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
clt = client.AcsClient("<your AccessKey ID>", "<your AccessKey secret>", "cn-shanghai")
region_provider.modify_point('Green', 'cn-shanghai', 'green.cn-shanghai.aliyuncs.com')
# Create a new request for each call. Do not reuse request objects.
request = ListSimilarityLibrariesRequest.ListSimilarityLibrariesRequest()
request.set_accept_format('JSON')
# pageSize: the size of each page. Valid values: (0, 50]. currentPage: the current page number. Valid values: (0, 50].
request.set_content(json.dumps({"pageSize": "5", "currentPage": "1"}))
try:
response = clt.do_action_with_exception(request)
print(response)
except Exception as err:
print(err)