Python - peewee - 调试语句 - 错误记录在哪里

Python - peewee - Debugging statements - where are the errors logged

我刚开始在 python 中使用 peewee。但是当我使用 .save() 函数保存 table 数据时。行中有错误。并且控制不会转到下一行。

只是想知道怎么才能知道是什么错误。虽然我已经缩小到下面的行

     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"

我使用了打印语句,我能够找出行 driver.save() 中的错误。但是如何检查到底是什么错误呢?

这在 peewee 文档中指定 here

将来,当您寻求帮助调试错误时,您还应该包括回溯。回溯会尽可能准确地告诉您出了什么问题。

如果你想做一些调试,你可以查看pdb(或者ipdb,如果你使用iPython):

https://docs.python.org/2/library/pdb.html

Peewee 将 DEBUG 级别的查询记录到 peewee 命名空间,因此您只需根据需要配置日志记录。根据 docs:

import logging

logger = logging.getLogger('peewee')
logger.addHandler(logging.StreamHandler())
logger.setLevel(logging.DEBUG)