Exception Handling
System Exception
BOS system exception is prompted in the following 3 ways
Exception method | Description |
---|---|
BceHttpClientError | Exception thrown during retry |
last_error | Exception thrown during the final retry |
BceClientError | Exception generated by BOS client |
BceInvalidArgumentError | Exception generated by introduced parameter |
BceServerError | Exception generated by BOS server |
You can use try to get exceptions generated by an event:
from baidubce import exception
from baidubce.services import bos
try:
bos_client.delete_object(bucket_name, object_key)
except exception.BceHttpError as e:
print e.message
Returned as:
BceHttpClientError: Unable to execute HTTP request. Retried 0 times. All trace backs:
Traceback (most recent call last):
File "/home/work/python-2.7/lib/python2.7/site-packages/baidubce/http/bce_http_client.py", line 184, in send_request
if handler_function(http_response, response):
File "/home/work/python-2.7/lib/python2.7/site-packages/baidubce/http/handler.py", line 71, in parse_error raise bse
BceServerError: The specified key does not exist.
Client Exception
Client exception indicates an exception encountered when the client attempts to send a request to the BOS and transmits data. For example, when the network connection is unavailable during request sending, BceHttpClientError is thrown; in case of IO exception during file upload, BceClientError is also thrown.
Server Exception
When an exception occurs on the BOS server, the BOS server returns the corresponding error message to the user to locate the problem. Common server exceptions can be found in BOS Error Message Format.
Parameter Exception
Each call of BOS Python SDK has some parameters that cannot be null with type fixed, and if such parameter returns a null value, ValueError is returned, and if such parameter introduces type error, TypeError is returned.
The relationship between parameters and calling is as follows:
BOS calling | parameter | description | type |
---|---|---|---|
create_bucket, does_bucket_exist, delete_bucket, get_bucket_location, get_bucket_lifecycle, delete_bucket_lifecycle, get_bucket_cors, delete_bucket_cors, get_bucket_logging, delete_bucket_logging, list_objects, list_all_objects, delete_object, get_bucket_acl, list_multipart_uploads, list_all_multipart_uploads | bucket_name | bucket name | string, unicode |
put_bucket_logging | source_bucket-target_bucket | Name of source bucket and target bucket | string, unicode |
set_bucket_acl | bucket_name | bucket name | string, unicode |
acl | ACL body contains authorized person and permission | list, dict | |
set_bucket_canned_acl | bucket_name | bucket name | string, unicode |
canned_acl | CannedAcl permission | string | |
put_bucket_lifecycle | bucket_name | bucket name | string, unicode |
rules | Lifecycle management rule body, containing resources and operation action | list, dict | |
put_bucket_cors | bucket_name | bucket name | string, unicode |
cors_configuration | Cross-origin resource sharing (CORS) rule body, containing source of permitted cross-origin request, permitted header, etc. | list, dict | |
get_object, get_object_as_string, get_object_meta_data, initiate_multipart_upload, generate_pre_signed_url | bucket_name | bucket name | string, unicode |
key | object name | string | |
get_object_to_file, put_object_from_file | bucket_name | bucket name | string, unicode |
key | object name | string | |
file_name | File name | string | |
put_object, append_object | bucket_name | bucket name | string, unicode |
key | object name | string | |
data | Stream object | object | |
content_length | Upload size of object | int, long | |
content_md5 | Upload MD5 of object | string | |
put_object_from_string-append_object_from_string | bucket_name | bucket name | string, unicode |
key | object name | string | |
data | Upload string | string, unicode | |
copy_object | source_bucket_name, target_bucket_name | Name of source bucket and target bucket | string, unicode |
source_key, target_key | Name of source object and target object | string | |
upload_part | bucket_name, upload_id | bucket name, identify MultUpload operation global ID | string, unicode |
key | object name | string | |
part_number | Part number | int | |
part_size | Upload part size | int, long | |
part_fp | Upload part object | object | |
upload_part_from_file | bucket_name, upload_id | bucket name, identify MultUpload operation global ID | string, unicode |
key | object name | string | |
part_number | Part number | int | |
part_size | Upload part size | int, long | |
file_name | File name | string | |
offset | offset starting position of part | int | |
complete_multipart_upload | bucket_name, upload_id | bucket name, identify MultUpload operation global ID | string, unicode |
key | object name | string | |
part_list | Part list | list | |
abort_multipart_upload, list_parts, list_all_parts | bucket_name, upload_id | bucket name, identify MultUpload operation global ID | string, unicode |
key | object name | string | |
delete_multiple_objects | bucket_name | bucket name | string, unicode |
key_list | object list | list |