Arc*_*her 1 python mysql try-catch peewee
我刚刚开始在python中使用peewee。但是当我使用 .save() 函数保存表数据时。线路中有错误。并且控制不会转到下一行。
只是想知道如何知道错误是什么。虽然我已经缩小到下面的行
try:
with database.transaction():
driver = Driver()
driver.person = person
driver.qualification = form.getvalue('qualification')
driver.number = form.getvalue('phone')
driver.license = form.getvalue('issu')
driver.audited_by = 0
print "this line prints"
driver.save()
print "this one does not print"
print "Success"
except:
print "Error"
Run Code Online (Sandbox Code Playgroud)
我使用了打印语句,我能够找出 driver.save() 行中的错误。但是如何检查错误究竟是什么?
Peewee 将 DEBUG 级别的查询记录到 peewee 命名空间,因此您只需根据需要配置日志记录。根据文档:
import logging
logger = logging.getLogger('peewee')
logger.addHandler(logging.StreamHandler())
logger.setLevel(logging.DEBUG)
Run Code Online (Sandbox Code Playgroud)