BcmClient
Create BcmClient
BcmClient serves as the client for BCM services, offering developers various methods to interact with BCM services.
Access BCM via AK/SK
-
Before creating BcmClient, a configuration file must be created to configure BcmClient. Below, this configuration file is named
bcm_sample_conf.py, with the following specific configuration information:#!/usr/bin/env python #coding=utf-8
#Import Python standard logging module import logging
#Import BCE configuration management module and security authentication module from Python SDK from baidubce.bce_client_configuration import BceClientConfiguration from baidubce.auth.bce_credentials import BceCredentials
#Set BcmClient Host, Access Key ID, and Secret Access Key bcm_host = "bcm.bj.baidubce.com" access_key_id = "AK" secret_access_key = "SK"
#Set log file handles and log levels logger = logging.getLogger('baidubce.http.bce_http_client') fh = logging.FileHandler("sample.log") fh.setLevel(logging.DEBUG)
#Set the order, structure and content of log file output formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') fh.setFormatter(formatter) logger.setLevel(logging.DEBUG) logger.addHandler(fh)
#Create BceClientConfiguration instance config = BceClientConfiguration(credentials=BceCredentials(access_key_id, secret_access_key), endpoint = bcm_host)
Note: For log files, Logging offers the following levels: DEBUG, INFO, WARNING, ERROR, and CRITICAL.
In the code above, access_key_id corresponds to “Access Key ID” in the console. secret_access_key corresponds to “Access Key Secret” in the console. For the method to retrieve them, refer to Manage ACCESSKEY.
The method above requires users to specify the BCM server domain name by themselves, which can be assigned to the bcm_host variable.
-
After completing the configurations above, refer to the following code to create a BcmClient.
#Import BcmClient configuration file import bcm_sample_conf #Import related BCM modules from baidubce import exception from baidubce.services import bcm from baidubce.services.bcm.bcm_client import BcmClient #Create a new BcmClient bcm_client = BcmClient(bcm_sample_conf.config)
