本文主要给大家介绍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接口详情,很多读者朋友肯定多少有一定的了解,如需获取更多的行业知识信息 ,可以持续关注我们的行业资讯栏目的。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。