IBM / ibm-cos-sdk-python

ibm-cos-sdk-python
Apache License 2.0
44 stars 26 forks source link

IBM Cloud object storage code snippet not working #58

Closed janpeter123 closed 2 weeks ago

janpeter123 commented 8 months ago

Problem Description

The code snippet available on this official documentation does not work properly. https://cloud.ibm.com/docs/cloud-object-storage?topic=cloud-object-storage-python

When I try to copy and paste from both the client approach and the resource approach the example function provided to list my buckets does not work.

On the documentation is not clear at all of which method the user should be using if it's the client approach or the resource approach.

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))

Problem Solution

What it worked for me was the following snippet

bucket_name = '<Bucket name>'
bucket_files = cos_client.list_objects(Bucket=bucket_name)

for file in bucket_files['Contents']:
    print(file['Key'])

Please change the documentation, it took a long time for me an ibmer used to IBM products to find the correct way. What I needed to do was to generate code automatically through cloud pak for data. Clients would take a lot longer.

IBM-diksha commented 7 months ago

Thank you @janpeter123 for informing , we have created an internal ticket for this and we will be updating the documentation in the next release.

avinash1IBM commented 2 months ago

@janpeter123 The documentation issues are fixed. Can you please check and close this ticket.

IBMalok commented 2 weeks ago

Closing as fix already provided.