Initialization
Confirm Endpoint
Before configuring the Endpoint for SDK usage, please refer to the developer guide section on Service Domains to understand Endpoint-related concepts. Baidu AI Cloud currently supports multiple regions. Please refer to Region Selection Guide.
Create EtClient
Create EtClient with AK/SK
Users can refer to the following code to create an EtClient to access BOS with AK/SK:
1from baidubce import bce_client_configuration
2from baidubce.services.blb import blb_client
3from baidubce.auth import bce_credentials
4class Sample():
5 def setUp(self):
6 AK = 'your-access-key-id' # User's Access Key ID
7 SK = 'your-secret-access-key' # User's Secret Access Key
8# Initialize a BlbClient
9 config = BceClientConfiguration(credentials=BceCredentials(AK, SK))
10 client = et_client.EtClient(config)
In the code above, AK corresponds to the "Access Key ID" in the console, and SK corresponds to the "Access Key Secret" in the console. For the access method, please refer to the Operation Guide for Managing Access Key.
By default, the above method assigns the default domain as BLB’s service address. However, to specify a custom domain name, you need to include the ENDPOINT parameter.
1 AK = 'your-access-key-id' # User's Access Key ID
2 SK = 'your-secret-access-key' # User's Secret Access Key
3 HOST = 'domain-name' # User-specified domain name. For domain selection, refer to the "Region List" below
4# Initialize an EtClient
5 config = BceClientConfiguration(credentials=BceCredentials(AK, SK), endpoint=HOST)
6 client = et_client.EtClient(config)
Note:
The ENDPOINTparameter must use region-specific domain names (e.g., http://aihc.bj.baidubce.com for Beijing). If unspecified, it defaults to the Beijing regionhttp://bcc.bj.baidubce.com.
