MYSQL 的数据序列化Api接口详情
发布时间:2020-04-29 17:02:59
来源:亿速云
阅读:158
作者:三月
本文主要给大家介绍MYSQL 的数据序列化Api接口详情,文章内容都是笔者用心摘选和编辑的,MYSQL 的数据序列化Api接口详情具有一定的针对性,对大家的参考意义还是比较大的,下面跟笔者一起了解下主题内容吧。
from flask import Flask
from flask import request, Response
app = Flask(__name__)
import os
def getApolloconf(k):
import requests
env = os.environ.get("RUNTIME_ENV") or "dev"
getApolloconfig = requests.get(
'http://configserver-{env}.chj.cloud/configs/op-bmc-api/default/application'.format(env=env))
data = getApolloconfig.json()["configurations"]
return data.get(k)
#######获取配置插入数据库#########
def mysqlConfig(sql):
import pymysql
import json
USERNAME = getApolloconf("USERNAME")
PASSWORD = getApolloconf("PASSWORD")
HOST = getApolloconf("HOST")
DATABASE = getApolloconf("NGINXDATABASE")
dbconfig = pymysql.connect(HOST, USERNAME, PASSWORD, DATABASE)
try:
cursor = dbconfig.cursor()
try:
cursor.execute(sql)
results = cursor.fetchall()
reultData=[]
columnList=["run_type","upstreamname","front_listen","domain_name","backend_ip"]
for row in results:
reultData.append(dict(zip(columnList, list(row))))
str1=(json.dumps(reultData, ensure_ascii=False))
return str1
except Exception as e:
pass
except Exception as err:
print(err)
def nginxtbale():
try:
sql = "select run_type,upstreamname,front_listen,domain_name,backend_ip from nginxManager_dj_nginx_conf order by create_time"
return mysqlConfig(sql)
except Exception as e:
# 如果发生错误则回滚
print(e)
@app.route('/')
def index():
import json
return Response(json.dumps(nginxtbale()), mimetype='application/json')
if __name__ == '__main__':
app.run(
host="192.168.1.1",
port=8008,
debug=True
)
看完以上关于MYSQL 的数据序列化Api接口详情,很多读者朋友肯定多少有一定的了解,如需获取更多的行业知识信息 ,可以持续关注我们的行业资讯栏目的。