创建TsdbClient
更新时间:2021-11-29
TSDB的数据接口在Python SDK中通过TsdbClient对象来访问,用户可以参考如下代码新建一个TsdbClient:
import baidubce.protocol
from baidubce.bce_client_configuration import BceClientConfiguration
from baidubce.auth.bce_credentials import BceCredentials
from baidubce.services.tsdb.tsdb_client import TsdbClient
# when use https as the protocol, you may find certificate expire problem, this can be resovled by adding the following lines
# import ssl
# ssl._create_default_https_context = ssl._create_unverified_context
##########必填配置#############
HOST = 'Fill host here' # 用户的时序数据库域名,形式如databasename.tsdb.iot.gz.baidubce.com
AK = 'Fill AK here' # 用户的百度智能云 Access Key ID
SK = 'Fill SK here' # 用户的百度智能云 Secret Access Key
###########可选配置#############
#使用HTTP协议
protocol=baidubce.protocol.HTTP
#使用HTTPS协议
# protocol= baidubce.protocol.HTTPS
connection_timeout_in_mills=None #连接超时时间
send_buf_size=None #发送缓冲区大小
recv_buf_size=None #接收缓冲区大小
retry_policy=None #重试策略
#生成config对象
config = BceClientConfiguration(
credentials=BceCredentials(AK, SK),
endpoint=HOST,
protocol=protocol,
connection_timeout_in_mills=connection_timeout_in_mills,
send_buf_size=send_buf_size,
recv_buf_size=recv_buf_size,
retry_policy=retry_policy)
#创建TsdbCient
tsdb_client = TsdbClient(config)
通过IP访问
在一些场景下比如正向代理,无法采用域名直接访问tsdb,python sdk也支持通过IP访问
##########必填配置#############
# HOST = '<ip>:<port>'
# AK = '<your ak>'
# SK = '<your sk>'
# DATABASE = '<database_name>'
########生成config对象########
config = BceClientConfiguration(
credentials=BceCredentials(AK, SK),
endpoint=HOST,
protocol=protocol,
connection_timeout_in_mills=connection_timeout_in_mills,
send_buf_size=send_buf_size,
recv_buf_size=recv_buf_size,
retry_policy=retry_policy)
########创建TsdbCient########
tsdb_client = TsdbClient(config,DATABASE)