Initializing a BucketClient Instance (SDK for Python)
Function
BucketClient functions as the Python client for accessing an OBS bucket. It offers users a series of APIs for interaction with OBS. These APIs are used for managing resources, such as buckets and objects, stored in OBS.
Except for ObsClient.listBuckets, ObsClient.downloadFile, Obsclient.uploadFile, ObsClient.createPostSignature, and ObsClient.createSignedUrl, BucketClient implements the same APIs as ObsClient, including the same functions and parameters, with the bucketName parameter omitted.
Method
obsClient.bucketClient( bucketName='*** Your Bucket Name ***' )
Constructor Parameter Description
Parameter |
Type |
Mandatory (Yes/No) |
Description |
---|---|---|---|
bucket_name |
str |
Yes |
Name of the bucket client to be created |
Code Examples
# Import the module. from obs import ObsClient # Obtain an AK and SK pair using environment variables or import the AK and SK pair in other ways. Using hard coding may result in leakage. # Obtain an AK and SK pair on the management console. For details, see https://support.huaweicloud.com/intl/en-us/usermanual-ca/ca_01_0003.html. ak = os.getenv("AccessKeyID") sk = os.getenv("SecretAccessKey") # (Optional) If you use a temporary AK and SK pair and a security token to access OBS, obtain them from environment variables. security_token = os.getenv("SecurityToken") # Set server to the endpoint corresponding to the bucket. CN-Hong Kong is used here as an example. Replace it with the one currently in use. server = "https://obs.ap-southeast-1.myhuaweicloud.com" # Create an obsClient instance. # If you use a temporary AK and SK pair and a security token to access OBS, you must specify security_token when creating an instance. obsClient = ObsClient(access_key_id=ak, secret_access_key=sk, server=server) # Create an instance of BucketClient. bucketClient = obsClient.bucketClient('bucketname') # Create a Bucket. resp = bucketClient.createBucket() if resp.status < 300: print('requestId:', resp.requestId) else: print('errorCode:', resp.errorCode) print('errorMessage:', resp.errorMessage)
Except for ObsClient.listBuckets, ObsClient.downloadFile, Obsclient.uploadFile, ObsClient.createPostSignature, and ObsClient.createSignedUrl, BucketClient can implement the same APIs as ObsClient, including the same functions and parameters, with the bucketName parameter omitted.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot