您好,登錄后才能下訂單哦!
本文主要給大家介紹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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。