Reputation: 61
I am trying to get all the bucket names in my IBM cloud object storage account: Passing the return value from connect() method to get_buckets(cos) method. Here is the code segment.
def connect():
# Create resource
cos = ibm_boto3.resource("s3",
ibm_api_key_id=COS_API_KEY_ID,
ibm_service_instance_id=COS_INSTANCE_CRN,
config=Config(signature_version="oauth"),
endpoint_url=COS_ENDPOINT
)
return cos
def get_buckets(cos):
print("Retrieving list of buckets")
print(cos.buckets.all())
The value used in COS_ENDPOINT = "https://control.cloud-object-storage.cloud.ibm.com/v2/endpoints"
Here is the error that I see:
python3.8/site-packages/ibm_botocore/parsers.py", line 432, in _parse_xml_string_to_dom parser.feed(xml_string) xml.etree.ElementTree.ParseError: not well-formed (invalid token): line 1, column 0
During handling of the above exception, another exception occurred:
...
File "/usr/local/lib/python3.8/site-packages/ibm_botocore/parsers.py", line 435, in _parse_xml_string_to_dom raise ResponseParserError( ibm_botocore.parsers.ResponseParserError: Unable to parse response (not well-formed (invalid token): line 1, column 0), invalid XML received:
Any help is appreciated, Thank you!
Upvotes: 1
Views: 581
Reputation: 534
I had this exact issue and realised that the issue is with the COS endpoint you are putting in. I made the mistake of seeing the "endpoints" value in the service credentials of the IBM COS instance and thinking that was the endpoint to access COS from the SDK. What it actually is is a JSON list of all the different endpoints available for all the different regions (public, private and direct versions of each region). This is why boto3 is complaining about getting JSON when it's expecting XML.
If you visit the "endpoints" URL at https://control.cloud-object-storage.cloud.ibm.com/v2/endpoints you can see all the available values for the different regions & sites but most of the time you'll just want to use the public one for your region, i.e.:
https://s3.{region}.cloud-object-storage.appdomain.cloud
where {region}
is e.g. eu-gb
, us-east
, ca-tor
, etc.
Upvotes: 1