- Documentation
Torch Object Storage
SDK Reference
Python
Bucket interface
Basic bucket interface
Get bucket region (Python SDK)
Basic bucket interface
Get bucket region (Python SDK)
Get bucket region (Python SDK)
Bucket is the globally unique namespace of TOS, which is equivalent to a data container and is used to store object data. This article describes how to obtain the regional information where the bucket is located.
Precautions
By default, only the owner of the bucket can view the area where the bucket is located.
Sample code
The following code is used to get the Region where the bucket-testis located.
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)
out = client.get_bucket_location(bucket_name)
print('region={}'.format(out.region))
print('extranet_endpoint={}'.format(out.extranet_endpoint))
print('intranet_endpoint={}'.format(out.intranet_endpoint))
except tos.exceptions.TosClientError as e:
print('fail with client error, message:{}, cause: {}'.format(e.message, e.cause))
except tos.exceptions.TosServerError as e:
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('with unknown error: {}'.format(e))
Last updated: 2025.09.17 18:22:12