我正在使用Python SDK for IBM Cloud Object Storage并希望循环所有可见的bucket并返回它们的位置。我面临的问题是,对于某些bucket,会返回一个错误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'])
我现在求助于这个解决方法:
它试图获取位置。如果失败,则分配None,当转换为JSON时,很好地转换为null。你知道吗
相关问题 更多 >
编程相关推荐