我正在使用用于IBM对象存储的Python,并希望循环所有可见的桶并返回它们的位置。我面临的问题是,对于某些桶,返回一个错误The specified bucket does not exist.
。根据这是由不同的存储类型引起的。的说法。
无论如何,我如何处理它,并至少获得可访问的桶的位置?下面是粗略的Python代码:
cos = ibm_boto3.client('s3',
ibm_api_key_id=api_key,
ibm_service_instance_id=service_instance_id,
ibm_auth_endpoint=auth_endpoint,
config=Config(signature_version='oauth'),
endpoint_url=service_endpoint)
# Call COS to list current buckets
response = cos.list_buckets()
# Get a list of all bucket names from the response
buckets = [bucket['Name'] for bucket in response['Buckets']]
print(response)
for bucketname in buckets:
print(bucketname, cos.get_bucket_location(Bucket=bucketname)['LocationConstraint'])
发布于 2019-02-28 15:18:52
我现在求助于这个解决办法:
def locations(buckets):
locs={}
for b in buckets:
try:
locs[b]=cos.get_bucket_location(Bucket=b)['LocationConstraint']
except:
locs[b]=None
pass
return locs
它试图找到那个位置。如果失败,则分配None,当转换为JSON时,这将很好地转换为null。
https://stackoverflow.com/questions/54902477
复制相似问题