Listing Buckets

API Description

You can use this API to obtain the bucket list. In the list, bucket names are displayed in lexicographical order.

Method Definition

ObsClient.listBuckets(isQueryLocation)

Request Parameters

Field

Type

Optional or Mandatory

Description

isQueryLocation

bool

Optional

Whether to query the bucket location

Returned Results

Type

Description

GetResult

SDK common result object

GetResult.body Type

Description

ListBucketsResponse

Response result of the request for listing buckets

Sample Code

try:
    resp = obsClient.listBuckets(True) 
    if resp.status < 300: 
        print('requestId:', resp.requestId) 
        print('name:', resp.body.owner.owner_id) 
        print('create_date:', resp.body.owner.owner_name) 
        index = 1 
        for bucket in resp.body.buckets: 
            print('bucket [' + str(index) + ']') 
            print('name:', bucket.name) 
            print('create_date:', bucket.create_date) 
            print('location:', bucket.location)
            index += 1 
    else: 
        print('errorCode:', resp.errorCode) 
        print('errorMessage:', resp.errorMessage)
except:
    import traceback
    print(traceback.format_exc())