def get_data():
conn = pymysql.connect(host=RSYS_HOST,
port=RSYS_PORT,
user=RSYS_USER,
passwd=RSYS_PASSWORDD,
db=RSYS_DB_NAME,
charset='utf8')
results = None
try:
read_result = pd.read_sql(sql, conn)
result_json = json.loads(read_result.reset_index().to_json(orient='records', force_ascii=False))
logger.info(sql)
return result_json
except Exception as e:
# 发生错误时回滚
logger.error("Error: unable to fecth data: %s,%s" % (repr(e), sql))
conn.rollback()
finally:
conn.close()
return results
02-13
495
06-12
1014
09-26
1万+
04-11
696