Creating an Instance
This section describes how to create an instance using AK/SK authentication.
Replace the AK/SK in the sample code with the actual AK/SK. Set the name and model parameters in the initialized CreateInstanceReq command to configure the instance name and model. After the configuration is complete, run the code.
- The sample code for creating 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 = RunCreateInstanceRequest() # Set parameters to create an instance. request.body = CreateInstanceReq( name="instance-name", # Name model="common-search", # Model tags=["animal", "plant"] # Tag ) response = client.run_create_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)
- Execute the sample code. If 200 is displayed on the console, the code is successfully executed. For details, see Creating an Instance.
200 {"domain": "general image search", "desc": "", "registerDate": 1637548249353, "expiredDate": -1, "level": 30000000, "tags": ["animal", "plant"], "status": "NORMAL", "instanceName": "instance-name"} Process finished with exit code 0
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.
For any further questions, feel free to contact us through the chatbot.
Chatbot