edit-icon download-icon

Handle errors

Last Updated: Mar 20, 2018

Alibaba Cloud Python SDK 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 these returned errors. You do need to make corresponding modifications based on the error message.

For example, modify the AccessKey ID when the following error is returned:

aliyunsdkcore.acs_exception.exceptions.ServerException:HTTP Status:404 Error:InvalidAccessKeyId.NotFound Specified access key is not found. RequestID:

If you want to add business logic for returned errors, you can write your code as follows:

  1. try:
  2. response = client.do_action_with_exception(request)
  3. except ServerException as e:
  4. # Add your business logic here
  5. # For example, print errors
  6. print e.get_http_status()
  7. print e.get_error_code()
  8. print e.get_error_msg()
Thank you! We've received your feedback.