一、利用configparser读取server.conf文件的内容
server.conf:
[api_server] #节点,使用的接口服务器代号为api_server
ip=x.x.x.x
port=端口号
[db_server]
host=x.x.x.x
db= 数据库名称
user= 用户名
passwd=密码
代码
import configparser,pymysql,pandas,requests
# 读取server.conf文件内容
conf = configparser.ConfigParser()
conf.read('server.conf',encoding='utf-8')
which_server ='api_server'
ip = conf.get(which_server,'ip')
port = conf.get(which_server,'port')
base_url = f"http://{ip}:{port}"
# 获取数据库服务的信息
which_db = 'db_server'
host = conf.get(which_db,'host')
db = conf.get(which_db,'db')
user = conf.get(which_db,'user')
passwd = conf.get(which_db,'passwd')
db_info = {'host':host,'db':db,'user':user,'passwd':passwd}