• Object Storage Service

obs
  1. Help Center
  2. Object Storage Service
  3. API Reference (Python SDK)
  4. Bucket-Related APIs
  5. HEAD Bucket

HEAD Bucket

API Description

You can use this API to check whether a bucket exists. If the returned HTTP status code is 200, the bucket exists. If the returned HTTP status code is 404, the bucket does not exist.

Method Definition

ObsClient.headBucket(bucketName)

Request Parameter

Field

Type

Optional or Mandatory

Description

bucketName

str

Mandatory

Bucket name

Returned Result

Type

Description

GetResult

SDK common result object

Sample Code

try:
    resp = obsClient.headBucket('bucketname') 
     
    if resp.status < 300: 
        print('Bucket exists') 
    elif resp.status == 404: 
        print('Bucket does not exist')
except:
    import traceback
    print(traceback.format_exc())