所以我有一个flask API端点,如下所示
所以现在我遇到的问题是,假设我运行了这个查询
"Select * from tables where IP = '123'" -> returns "Capacity" : 80但是,我随后进入我的数据库本身,并将容量编辑为50。注意:通过数据库控制台本身,而不是API。
然而,rest API需要5-10分钟才能看到表中的变化!在rest API中对端点执行相同的查询仍然返回80,即使表中的相同查询返回50。
flask应用程序本身是否正在进行某些缓存?
编辑:当我重新连接到数据库时,似乎工作正常...嗯
db = MySQLdb.connect("address","iuser","pass","table")
cursor = db.cursor()
@app.route('/sqlStatement', methods=['POST'])
def run_statement():
try:
statement = request.values['statement']
try:
cursor.execute(statement)
except mysql.connector.Error: #MySQLdb.Warning) as e:
return "BAD SQL STATEMENT DUMBASS"
return jsonify(data=cursor.fetchall())
except (AttributeError, MySQLdb.OperationalError):
open_db()
return run_statement()发布于 2017-02-24 09:45:39
缺少db.commit() :)
在我使用我的代码尝试插入数据后,我注意到了这一点,但它在读取时工作得很好,同时也保持了数据库的一致性。启用自动提交也可以解决这个问题。
https://stackoverflow.com/questions/42406721
复制相似问题