Checking Whether a Bucket Exists
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 Parameters
|
Field |
Type |
Optional or Mandatory |
Description |
|---|---|---|---|
|
bucketName |
str |
Mandatory |
Bucket name |
Returned Results
|
Type |
Description |
|---|---|
|
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())
Last Article: Listing Buckets
Next Article: Deleting a Bucket
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.