Feature Overview
If an XML Python SDK operation is successful, the system will return
dict or None. If an SDK API call to request the COS service fails, the system will throw CosClientError (client exception) or CosServiceError (server exception).The client exception,
CosClientError, results from unexpected interaction issues between the client and the COS server, such as a failure to connect to the server, a failure to parse the data returned by the server, or the occurrence of an IO exception when reading a local file.The server exception,
CosServiceError, occurs when the client interacts with the COS server normally, but the operation fails. For example, the client accesses a bucket that does not exist, deletes an object that does not exist, or does not have the permission to perform an operation.Client Exceptions
A
CosClientError generally refers to a client error caused by issues such as timeout. When capturing such an error, you can choose to retry or perform other operations.Server Exceptions
A
CosServiceError contains the detailed information returned by the server, including the status code, request ID, and error details. After such an exception is captured, it is recommended that you print out the entire exception as it contains necessary factors for troubleshooting. The following describes the member variables of the exception and provides an example of exception capturing.Member | Description | Local Disk Types |
request_id | Request ID, used to identify a request. It is very important for troubleshooting. | string |
status_code | string | |
error_code | string | |
error_msg | string |
Example of Exception Capturing
from qcloud_cos import CosServiceErrorexcept CosServiceError as e:e.get_origin_msg()# Retrieve the original error message in XML format.e.get_digest_msg()# Retrieve the processed error information in the form of a dictionary.e.get_status_code()# Retrieve the HTTP error code (such as 4XX, 5XX)e.get_error_code() # Retrieve the error code defined by COSe.get_error_msg()- Retrieve the detailed description of the COS error code.e.get_trace_id()# Retrieve the request's trace_ide.get_request_id()# Retrieve the request ID of the operatione.get_resource_location()# Retrieve the URL address
Using self-diagnose tools
COS provides a self-help diagnosis tool to help you quickly locate request errors and debug the code.
Directions
1. Copy the request ID (
RequestId) returned when the request error occurs.2. Click Diagnosis Tool.
3. Enter the RequestId to be diagnosed in the RequestId input box at the top, and click Start Diagnosis. Please wait patiently for a few minutes to view the corresponding intelligent diagnosis results.