All Products
Search
Document Center

Object Storage Service:Endpoint errors occur when you access buckets in OSS through SDKs

Last Updated:Mar 20, 2026

Symptom

When you use an OSS SDK to access a bucket, the following error is returned:

The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint

Cause

The endpoint parameter is missing or points to the wrong region. Each OSS bucket is tied to the region where it was created, and every request must use that region's endpoint.

For example, if a bucket is created in the Qingdao region but the SDK is initialized with the Hangzhou endpoint (oss-cn-hangzhou.aliyuncs.com), OSS rejects the request with this error.

Solution

Set the endpoint parameter to the endpoint of the region where your bucket was created.

The following examples show the correct initialization pattern.

import os
import oss2

# Use the endpoint that matches the region where your bucket was created.
# Full endpoint list: https://www.alibabacloud.com/help/en/oss/user-guide/regions-and-endpoints
endpoint = 'https://oss-cn-qingdao.aliyuncs.com'  # Replace with your bucket's region endpoint

access_key_id     = os.environ.get('OSS_ACCESS_KEY_ID')
access_key_secret = os.environ.get('OSS_ACCESS_KEY_SECRET')

auth   = oss2.Auth(access_key_id, access_key_secret)
bucket = oss2.Bucket(auth, endpoint, 'examplebucket')
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;

// Use the endpoint that matches the region where your bucket was created.
// Full endpoint list: https://www.alibabacloud.com/help/en/oss/user-guide/regions-and-endpoints
String endpoint = "https://oss-cn-qingdao.aliyuncs.com"; // Replace with your bucket's region endpoint

String accessKeyId     = System.getenv("OSS_ACCESS_KEY_ID");
String accessKeySecret = System.getenv("OSS_ACCESS_KEY_SECRET");

OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);

Replace https://oss-cn-qingdao.aliyuncs.com with the actual endpoint for your bucket's region. See Regions and endpoints for the full list.

Accessing buckets in multiple regions

If your application accesses buckets in different regions, create a separate client instance for each region with the corresponding endpoint.

import os
import oss2

access_key_id     = os.environ.get('OSS_ACCESS_KEY_ID')
access_key_secret = os.environ.get('OSS_ACCESS_KEY_SECRET')

auth = oss2.Auth(access_key_id, access_key_secret)

# Client for the Qingdao region
qingdao_bucket = oss2.Bucket(auth, 'https://oss-cn-qingdao.aliyuncs.com', 'examplebucket')

# Client for the Hangzhou region
hangzhou_bucket = oss2.Bucket(auth, 'https://oss-cn-hangzhou.aliyuncs.com', 'examplebucket')
String accessKeyId     = System.getenv("OSS_ACCESS_KEY_ID");
String accessKeySecret = System.getenv("OSS_ACCESS_KEY_SECRET");

// Client for the Qingdao region
OSS qingdaoClient = new OSSClientBuilder().build(
    "https://oss-cn-qingdao.aliyuncs.com",
    accessKeyId,
    accessKeySecret
);

// Client for the Hangzhou region
OSS hangzhouClient = new OSSClientBuilder().build(
    "https://oss-cn-hangzhou.aliyuncs.com",
    accessKeyId,
    accessKeySecret
);

References