Alibaba Cloud SDK for Python returns corresponding exceptions when an error occurs on the service side or the SDK side. These exceptions contain detailed error information, including the error code (ErrCode) and error message (ErrMsg).

You do not need to handle the errors returned by the Alibaba Cloud SDK for Python. You only need to handle server errors based on error messages generated on the server side.

  • ServerException is the exception returned by the corresponding Alibaba Cloud service.
  • ClientException is the exception returned by the Alibaba Cloud SDK for Python.

The following error indicates that the AccessKey ID is invalid. You must specify the correct AccessKey ID.

aliyunsdkcore.acs\_exception.exceptions.ServerException: HTTP Status: 404 Error:InvalidAccessKeyId.NotFound Specified access key is not found.

The following code provides an example on how to handle errors returned by the Alibaba Cloud SDK for Python.

try:
    response = client.do_action_with_exception(request)
except ServerException as e:
    # Add your own computing logic for handling errors here.
    # For example, you can obtain the error information.
    print e.get_http_status()
    print e.get_error_code()
    print e.get_error_msg()