• Object Storage Service

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

PUT Bucket website

API Description

You can use this API to set website hosting for a bucket.

Method Definition

ObsClient.setBucketWebsiteConfiguration(bucketName, website)

Request Parameter

Field

Type

Optional or Mandatory

Description

bucketName

str

Mandatory

Bucket name

website

WebsiteConfiguration

Mandatory

Website hosting settings of the bucket

Returned Result

Type

Description

GetResult

SDK common result object

Sample Code

try:
    from com.obs.models.website_configuration import WebsiteConfiguration 
    from com.obs.models.index_document import IndexDocument 
    from com.obs.models.error_document import ErrorDocument 
    from com.obs.models.routing_rule import RoutingRule 
    from com.obs.models.condition import Condition 
    from com.obs.models.redirect import Redirect 
     
    errorDocument = ErrorDocument(key='error.html') 
    indexDocument = IndexDocument(suffix='index.html') 
    routingRule1 = RoutingRule(condition=Condition(httpErrorCodeReturnedEquals=404), redirect=Redirect(protocol='http', replaceKeyWith='NotFound.html')) 
    routingRule2 = RoutingRule(condition=Condition(httpErrorCodeReturnedEquals=404), redirect=Redirect(protocol='https', replaceKeyWith='test.html')) 
    routingRules = [routingRule1, routingRule2] 
     
    resp = obsClient.setBucketWebsiteConfiguration('bucketname', WebsiteConfiguration(errorDocument=errorDocument, indexDocument=indexDocument, routingRules=routingRules)) 
      
    if resp.status < 300: 
        print('requestId:', resp.requestId) 
    else: 
        print('errorCode:', resp.errorCode) 
        print('errorMessage:', resp.errorMessage)
except:
    import traceback
    print(traceback.format_exc())