【问题标题】:Unhandled Exception due to failure importing database file. How to fix?由于导入数据库文件失败而导致未处理的异常。怎么修?
【发布时间】:2022-12-03 00:26:30
【问题描述】:

我在 pythonanywhere 上托管了一个 Flask 网站,但在访问该网站时,我一直收到“未处理的异常”错误。我检查了错误日志,问题出在一个名为 finance.db 的数据库文件上。错误日志中的确切文本如下:

2022-04-26 07:23:21,225: Error running WSGI application
2022-04-26 07:23:21,239: RuntimeError: does not exist: finance.db
2022-04-26 07:23:21,240:   File "/var/www/routsiddharth_pythonanywhere_com_wsgi.py", line 16, in <module>
2022-04-26 07:23:21,240:     from app import app as application  # noqa
2022-04-26 07:23:21,240: 
2022-04-26 07:23:21,240:   File "/home/routsiddharth/mysite/app.py", line 39, in <module>
2022-04-26 07:23:21,240: 
2022-04-26 07:23:21,240:   File "/home/routsiddharth/.local/lib/python3.9/site-packages/cs50/sql.py", line 60, in __init__
2022-04-26 07:23:21,240:     raise RuntimeError("does not exist: {}".format(matches.group(1)))
2022-04-26 07:23:21,241: ***************************************************
2022-04-26 07:23:21,241: If you're seeing an import error and don't know why,
2022-04-26 07:23:21,241: we have a dedicated help page to help you debug: 
2022-04-26 07:23:21,241: https://help.pythonanywhere.com/pages/DebuggingImportError/
2022-04-26 07:23:21,241: ***************************************************

这是我导入文件的方式:

from cs50 import SQL
db = SQL("sqlite:///finance.db")

finance.db 文件与 app.py 文件位于同一目录中。

我该如何解决这个错误?

【问题讨论】:

    标签: python flask pythonanywhere


    【解决方案1】:

    您需要使用正确的路径引用数据库:https://help.pythonanywhere.com/pages/NoSuchFileOrDirectory/

    【讨论】:

      【解决方案2】:

      我有这个问题。

      假设我有一个名为“ tx.db ”的数据库文件

      这个路径正确吗? ''db = SQL("sqlite:///home/USERNAME/mysite/tx.db")''

      我用那个和 ''db = SQL("tx.db")''

      但它返回错误:RuntimeError:不存在:tx.db

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-12-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-01-29
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多