Huawei OBS Python SDK

raw JSON →
3.26.2 verified Fri May 01 auth: no python

The official Huawei Cloud Object Storage Service (OBS) Python SDK, providing APIs to manage buckets and objects on OBS. Current version 3.26.2 is released regularly.

pip install esdk-obs-python
error ModuleNotFoundError: No module named 'obs'
cause Installing the package but import fails because the module name is 'obs' not 'esdk_obs_python'.
fix
Use 'from obs import ObsClient' after installing esdk-obs-python.
error obs.ObsClient() got an unexpected keyword argument 'region'
cause Using an outdated initialization pattern with region parameter; current SDK expects server URL.
fix
Use ObsClient(access_key_id=ak, secret_access_key=sk, server='https://your-endpoint.com')
error AttributeError: 'NoneType' object has no attribute 'buckets'
cause Resp is None or error response has no body. Usually means network/authentication failure not caught.
fix
Check resp.status before accessing resp.body.
breaking In v3.x, import path changed from earlier SDK versions. Use 'from obs import ObsClient', not 'from esdk_obs_python import ...'.
fix Use correct import: from obs import ObsClient
gotcha The ObsClient must be closed explicitly to release resources. Not doing so can cause connection leaks.
fix Always call obsClient.close() after operations, or use a context manager wrapper.
gotcha HTTP status codes are not Python exceptions; check resp.status < 300. Do not assume success.
fix Inspect resp.status and handle error codes via resp.errorCode/resp.errorMessage.

Initialize ObsClient, list buckets, and handle errors.

from obs import ObsClient
import os

ak = os.environ.get('OBS_AK', '')
sk = os.environ.get('OBS_SK', '')
server = os.environ.get('OBS_SERVER', 'https://your-endpoint.com')

obsClient = ObsClient(access_key_id=ak, secret_access_key=sk, server=server)

resp = obsClient.listBuckets()
if resp.status < 300:
    for bucket in resp.body.buckets:
        print(bucket.name)
else:
    print(f"Error: {resp.errorCode} {resp.errorMessage}")

obsClient.close()