【发布时间】:2019-02-28 23:18:52
【问题描述】:
我正在使用Python SDK for IBM Cloud Object Storage 并希望遍历所有可见的存储桶并返回它们的位置。我面临的问题是,对于某些存储桶,会返回错误 The specified bucket does not exist.。根据this SO answer it is caused by different storage types.
尽管如此,我该如何处理它并至少获得可访问存储桶的位置?这是粗略的 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'])
【问题讨论】:
-
如何操作取决于您如何判断存储桶是否可访问。您是否可以检查可能缺少的属性?
标签: python amazon-s3 ibm-cloud object-storage