文档中心 > 获取桶的地域
获取桶的地域

最近更新时间:2021-09-22

以下代码用于获取桶的地域(称为Region或Location):

from src.ossConfig import ossConfig

import unicloud_oss.Oss as Oss

access_key = 'XXXXXXXXX'
secret_key = 'XXXXXXXXXXXXXXXXXXX'
endpoint_url = 'http://XXXXXXXXXXXXXXXXX.com'
config = ossConfig(access_key,secret_key,endpoint_url)

bucket_name = 'test1'

bucket_region = Oss.get_bucket_region(config, bucket_name)
if bucket_region is None:
   print('Error!')
else:
   print(f'   {bucket_region["LocationConstraint"]}')