Help Center/ ImageSearch/ SDK Reference/ Using the Python SDK/ Querying Details About an Instance
Updated on 2022-02-22 GMT+08:00

Querying Details About an Instance

This section describes how to query an instance using AK/SK authentication.

Replace the AK/SK in the sample code with the actual AK/SK. Set the instance_name parameter in the RunQueryInstanceRequest command to specify the name of the instance you want to query. After the configuration is complete, run the code.

  1. The sample code for querying an instance is as follows:
    # coding: utf-8 
     
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkimagesearch.v1 import *
    from huaweicloudsdkimagesearch.v1.region.imagesearch_region import ImageSearchRegion
     
    if __name__ == "__main__":
        #Set the obtained AK and SK.
        ak = "<YOUR AK>"
        sk = "<YOUR SK>"
     
        credentials = BasicCredentials(ak, sk)
     
        client = ImageSearchClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(ImageSearchRegion.value_of("cn-north-4")) \
            .build()
     
        try:
            request = RunQueryInstanceRequest()
            #Set the instance name.
            request.instance_name = "instance-name"
            response = client.run_query_instance(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)
  2. Execute the sample code. If the instance querying result is displayed on the console, the code is successfully executed. For details, see Querying the Details About an Instance.
    200 
     {"domain": "general image search", "desc": "", "registerDate": 1637548249353, "expiredDate": -1, "level": 30000000, "tags": ["animal", "plant"], "status": "NORMAL", "instanceName": "instance-name"}