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

时间:2015-04-26 06:00:22

标签: 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"

我使用了print语句,我能够在行driver.save()中找出错误。但是如何检查错误究竟是什么?

3 个答案:

答案 0 :(得分:1)

这在peewee文档here中指定。

答案 1 :(得分:0)

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

如果您想进行一些调试,可以查看pdb(或ipdb如果您使用iPython):

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

答案 2 :(得分:0)

Peewee在DEBUG级别将查询记录到peewee命名空间,因此您只需要根据需要配置记录即可。根据{{​​3}}:

import logging

logger = logging.getLogger('peewee')
logger.addHandler(logging.StreamHandler())
logger.setLevel(logging.DEBUG)
相关问题