从我的调试日志中,我发现我的进程已被中断,我在我的代码中设置了try-catch,如下所示,
try:
print "update query : ........"
query = ("Update Logs set id = "+str(id)+" where Sid = '"+str(id)+"'")
cursor.execute(query)
conn.commit()
except (MySQLdb.Error, MySQLdb.Warning) as e:
sqlerrlogs = open("/log/mysqlerr.log","a")
sqlerrlogs.write(str(datetime.now()))
sqlerrlogs.write('\n')
sqlerrlogs.write(e)
sqlerrlogs.write('\n\n')
但是从我的日志开始,打印后#34;更新查询:........" ,我的日志中没有错误,如何修复我的代码以了解发生了什么? 我的python版本是2.7
答案 0 :(得分:0)
您可以捕获所有错误,而不仅仅是与MySQLdb相关的错误:
import traceback
try:
print "update query : ........"
query = ("Update Logs set id = "+str(id)+" where Sid = '"+str(id)+"'")
cursor.execute(query)
conn.commit()
except:
err = traceback.format_exc()
sqlerrlogs = open("/log/mysqlerr.log","a")
sqlerrlogs.write(str(datetime.now()))
sqlerrlogs.write('\n')
sqlerrlogs.write(err)
sqlerrlogs.write('\n\n')