Adding Tags to a Bucket

API Description

You can use this API to add tags to a bucket. Tags are used to identify and classify OBS buckets. Each bucket can have up to 10 tags. The key and value of a tag can be in Unicode.

For more information, see Tags.

Method Definition

ObsClient.setBucketTagging(bucketName, tagInfo)

Request Parameters

Field

Type

Optional or Mandatory

Description

bucketName

str

Mandatory

Bucket name

tagInfo

TagInfo

Mandatory

Bucket tag settings

Returned Results

Type

Description

GetResult

SDK common result object

Sample Code

try:
    from obs import TagInfo 
     
    tagInfo = TagInfo() 
    tagInfo.addTag('tag1', 'value1').addTag('tag2', 'value2') 
     
    resp = obsClient.setBucketTagging('bucketname', tagInfo) 
      
    if resp.status < 300: 
        print('requestId:', resp.requestId) 
    else: 
        print('errorCode:', resp.errorCode) 
        print('errorMessage:', resp.errorMessage)
except:
    import traceback
    print(traceback.format_exc())