2

检索存储桶名称时,它向我显示此错误。

CLIENT ERROR: An error occurred (InvalidArgument) when calling the ListBuckets operation: Invalid Argument

还有一件事我想知道 COS_ENDPOINT 是否正确。因为它还在检索时向我显示了 XML 格式错误。这是代码:

import ibm_boto3
from ibm_botocore.client import Config, ClientError

# Constants for IBM COS values
COS_ENDPOINT = "https://s3.eu-gb.cloud-object-storage.appdomain.cloud"
COS_API_KEY_ID = "xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
COS_AUTH_ENDPOINT = "https://iam.bluemix.net/oidc/token"
SERVICE_INSTANCE_ID = "crn:v1:bluemix:public:iam-identity::a/xxxxxxxxxxxxxxxxxxx::serviceid:ServiceId-xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx"

# Create resource
cos = ibm_boto3.resource("s3",
    ibm_api_key_id=COS_API_KEY_ID,
    ibm_service_instance_id=SERVICE_INSTANCE_ID,
    ibm_auth_endpoint=COS_AUTH_ENDPOINT,
    config=Config(signature_version="oauth"),
    endpoint_url=COS_ENDPOINT
)

def get_buckets():
    print("Retrieving list of buckets")
    try:
        buckets = cos.buckets.all()
        for bucket in buckets:
            print("Bucket Name: {0}".format(bucket.name))
    except ClientError as be:
        print("CLIENT ERROR: {0}\n".format(be))
    except Exception as e:
        print("Unable to retrieve list buckets: {0}".format(e))

get_buckets()

请帮帮我。

提前致谢。

4

1 回答 1

1
import ibm_boto3
from ibm_botocore.client import Config, ClientError

# Constants for IBM COS values
COS_ENDPOINT = "https://s3.eu-gb.cloud-object-storage.appdomain.cloud"
COS_API_KEY_ID = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
COS_AUTH_ENDPOINT = "https://iam.bluemix.net/oidc/token"
SERVICE_INSTANCE_ID = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

“resource_instance_id”:“crn:v1:bluemix:public:cloud-object-storage:global:a/3c467ce9e6d84b90065fd00be3065964:65c5b3g2-7db5-4251-93a1-a7c33486d5e9::”

在服务实例 ID 中使用:65c5b3g2-7db5-4251-93a1-a7c33486d5e9(这不是我的 resource_instance_id

# Create resource
cos = ibm_boto3.resource("s3",
    ibm_api_key_id=COS_API_KEY_ID,
    ibm_service_instance_id=SERVICE_INSTANCE_ID,
    ibm_auth_endpoint=COS_AUTH_ENDPOINT,
    config=Config(signature_version="oauth"),
    endpoint_url=COS_ENDPOINT
)

for bucket in cos.buckets.all():
    print(bucket.name)

于 2020-09-20T06:07:29.443 回答