ak = os.getenv('TOS_ACCESS_KEY')
sk = os.getenv('TOS_SECRET_KEY')
endpoint = "your endpoint"
bucket_name = 'bucket-test'
client = tos.TosClientV2(ak, sk, endpoint, region)
head_bucket_out = client.head_bucket(bucket_name)
print('region: ', head_bucket_out.region)
print('storageClass: ', head_bucket_out.storage_class)
print('azRedundancy: ', head_bucket_out.az_redundancy)
except tos.exceptions.TosClientError as e:
print('fail with client error, message:{}, cause: {}'.format(e.message, e.cause))
except tos.exceptions.TosServerError as e:
if e.status_code == http.HTTPStatus.NOT_FOUND:
print('bucket not exist')
elif e.status_code == http.HTTPStatus.FORBIDDEN:
print('do not have head bucket policy')
print('fail with server error, code: {}'.format(e.code))
print('error with request id: {}'.format(e.request_id))
print('error with message: {}'.format(e.message))
print('error with http code: {}'.format(e.status_code))
print('error with ec: {}'.format(e.ec))
print('error with request url: {}'.format(e.request_url))
print('fail with unknown error: {}'.format(e))