【问题标题】:Apache running Flask on gcloud 500 Internal Server ErrorApache 在 gcloud 500 内部服务器错误上运行 Flask
【发布时间】:2020-03-01 16:16:24
【问题描述】:

我一直在尝试将我的烧瓶应用程序部署在 apache 网络服务器上,并让它发挥了一定的作用。 我现在面临的问题是,我需要在我的数据库中创建一个新条目(使用 peewee sqlite 来处理与数据库相关的所有内容)或对一个已经令人兴奋的条目进行更改的唯一页面我收到 500 Internal Server Error。

读取数据库时似乎功能齐全,但无法写入。我已将 .db 文件权限更新为 777,但这并没有帮助。

以下代码在 Flask 文件中,并声明了 .db 文件的路径:

APP_DIR = os.path.dirname(os.path.realpath(__file__))

# Specifying the path of the DB file
DATABASE = 'sqliteext:///%s' % os.path.join(APP_DIR, 'blog.db')

我在下面放置了最新的错误日志,它是在尝试创建新条目时发生的,非常感谢任何想法。

[Sun Mar 01 15:59:58.008931 2020] [wsgi:error] [pid 5311:tid 139974393460480] [client 86.52.107.75:54947] hello: INDEX, referer: http://35.204.127.172/26-th/
[Sun Mar 01 15:59:58.010272 2020] [wsgi:error] [pid 5311:tid 139974393460480] [client 86.52.107.75:54947] totentries no search:  26, referer: http://35.204.127.172/26-th/
[Sun Mar 01 15:59:58.011008 2020] [wsgi:error] [pid 5311:tid 139974393460480] [client 86.52.107.75:54947] SELECT "t1"."id", "t1"."auth", "t1"."title", "t1"."slug", "t1"."content", "t1"."published", "t1"."timestamp" FROM "entry" AS "t1" WHERE ("t1"."published" = 1) ORDER BY "t1"."timestamp" DESC LIMIT 7 OFFSET 0, referer: http://35.204.127.172/26-th/
[Sun Mar 01 15:59:59.766531 2020] [wsgi:error] [pid 5311:tid 139974385067776] [client 86.52.107.75:54947] rasmus1, referer: http://35.204.127.172/index
[Sun Mar 01 15:59:59.767495 2020] [wsgi:error] [pid 5311:tid 139974385067776] [client 86.52.107.75:54947] entry 26, referer: http://35.204.127.172/index
[Sun Mar 01 16:00:02.433956 2020] [wsgi:error] [pid 5311:tid 139974376675072] [client 86.52.107.75:54947] rasmus1, referer: http://35.204.127.172/26-th/
[Sun Mar 01 16:00:02.434670 2020] [wsgi:error] [pid 5311:tid 139974376675072] [client 86.52.107.75:54947] entry 26, referer: http://35.204.127.172/26-th/
[Sun Mar 01 16:00:02.435722 2020] [wsgi:error] [pid 5311:tid 139974376675072] [client 86.52.107.75:54947] 26, referer: http://35.204.127.172/26-th/
[Sun Mar 01 16:00:02.439363 2020] [wsgi:error] [pid 5311:tid 139974376675072] [client 86.52.107.75:54947] ERROR:FlaskApp:Exception on /26-th/ [POST], referer: http://35.204.127.172/26-th/
[Sun Mar 01 16:00:02.439380 2020] [wsgi:error] [pid 5311:tid 139974376675072] [client 86.52.107.75:54947] Traceback (most recent call last):, referer: http://35.204.127.172/26-th/
[Sun Mar 01 16:00:02.439384 2020] [wsgi:error] [pid 5311:tid 139974376675072] [client 86.52.107.75:54947]   File "/usr/local/lib/python3.5/dist-packages/peewee.py", line 3057, in execute_sql, referer: http://35.204.127.172/26-th/
[Sun Mar 01 16:00:02.439388 2020] [wsgi:error] [pid 5311:tid 139974376675072] [client 86.52.107.75:54947]     cursor.execute(sql, params or ()), referer: http://35.204.127.172/26-th/
[Sun Mar 01 16:00:02.439391 2020] [wsgi:error] [pid 5311:tid 139974376675072] [client 86.52.107.75:54947] sqlite3.OperationalError: unable to open database file, referer: http://35.204.127.172/26-th/
[Sun Mar 01 16:00:02.439394 2020] [wsgi:error] [pid 5311:tid 139974376675072] [client 86.52.107.75:54947] , referer: http://35.204.127.172/26-th/
[Sun Mar 01 16:00:02.439398 2020] [wsgi:error] [pid 5311:tid 139974376675072] [client 86.52.107.75:54947] During handling of the above exception, another exception occurred:, referer: http://35.204.127.172/26-th/
[Sun Mar 01 16:00:02.439401 2020] [wsgi:error] [pid 5311:tid 139974376675072] [client 86.52.107.75:54947] , referer: http://35.204.127.172/26-th/
[Sun Mar 01 16:00:02.439404 2020] [wsgi:error] [pid 5311:tid 139974376675072] [client 86.52.107.75:54947] Traceback (most recent call last):, referer: http://35.204.127.172/26-th/
[Sun Mar 01 16:00:02.439407 2020] [wsgi:error] [pid 5311:tid 139974376675072] [client 86.52.107.75:54947]   File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 2446, in wsgi_app, referer: http://35.204.127.172/26-th/
[Sun Mar 01 16:00:02.439410 2020] [wsgi:error] [pid 5311:tid 139974376675072] [client 86.52.107.75:54947]     response = self.full_dispatch_request(), referer: http://35.204.127.172/26-th/
[Sun Mar 01 16:00:02.439423 2020] [wsgi:error] [pid 5311:tid 139974376675072] [client 86.52.107.75:54947]   File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1951, in full_dispatch_request, referer: http://35.204.127.172/26-th/
[Sun Mar 01 16:00:02.439427 2020] [wsgi:error] [pid 5311:tid 139974376675072] [client 86.52.107.75:54947]     rv = self.handle_user_exception(e), referer: http://35.204.127.172/26-th/
[Sun Mar 01 16:00:02.439429 2020] [wsgi:error] [pid 5311:tid 139974376675072] [client 86.52.107.75:54947]   File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1820, in handle_user_exception, referer: http://35.204.127.172/26-th/
[Sun Mar 01 16:00:02.439432 2020] [wsgi:error] [pid 5311:tid 139974376675072] [client 86.52.107.75:54947]     reraise(exc_type, exc_value, tb), referer: http://35.204.127.172/26-th/
[Sun Mar 01 16:00:02.439435 2020] [wsgi:error] [pid 5311:tid 139974376675072] [client 86.52.107.75:54947]   File "/usr/local/lib/python3.5/dist-packages/flask/_compat.py", line 39, in reraise, referer: http://35.204.127.172/26-th/
[Sun Mar 01 16:00:02.439438 2020] [wsgi:error] [pid 5311:tid 139974376675072] [client 86.52.107.75:54947]     raise value, referer: http://35.204.127.172/26-th/
[Sun Mar 01 16:00:02.439441 2020] [wsgi:error] [pid 5311:tid 139974376675072] [client 86.52.107.75:54947]   File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1949, in full_dispatch_request, referer: http://35.204.127.172/26-th/
[Sun Mar 01 16:00:02.439444 2020] [wsgi:error] [pid 5311:tid 139974376675072] [client 86.52.107.75:54947]     rv = self.dispatch_request(), referer: http://35.204.127.172/26-th/
[Sun Mar 01 16:00:02.439447 2020] [wsgi:error] [pid 5311:tid 139974376675072] [client 86.52.107.75:54947]   File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1935, in dispatch_request, referer: http://35.204.127.172/26-th/
[Sun Mar 01 16:00:02.439450 2020] [wsgi:error] [pid 5311:tid 139974376675072] [client 86.52.107.75:54947]     return self.view_functions[rule.endpoint](**req.view_args), referer: http://35.204.127.172/26-th/
[Sun Mar 01 16:00:02.439452 2020] [wsgi:error] [pid 5311:tid 139974376675072] [client 86.52.107.75:54947]   File "/var/www/FlaskApp/FlaskApp/__init__.py", line 403, in detail, referer: http://35.204.127.172/26-th/
[Sun Mar 01 16:00:02.439455 2020] [wsgi:error] [pid 5311:tid 139974376675072] [client 86.52.107.75:54947]     create_comment(slug), referer: http://35.204.127.172/26-th/
[Sun Mar 01 16:00:02.439458 2020] [wsgi:error] [pid 5311:tid 139974376675072] [client 86.52.107.75:54947]   File "/var/www/FlaskApp/FlaskApp/__init__.py", line 364, in create_comment, referer: http://35.204.127.172/26-th/
[Sun Mar 01 16:00:02.439461 2020] [wsgi:error] [pid 5311:tid 139974376675072] [client 86.52.107.75:54947]     commentContent=request.form.get('comment'), referer: http://35.204.127.172/26-th/
[Sun Mar 01 16:00:02.439464 2020] [wsgi:error] [pid 5311:tid 139974376675072] [client 86.52.107.75:54947]   File "/usr/local/lib/python3.5/dist-packages/peewee.py", line 6235, in create, referer: http://35.204.127.172/26-th/
[Sun Mar 01 16:00:02.439466 2020] [wsgi:error] [pid 5311:tid 139974376675072] [client 86.52.107.75:54947]     inst.save(force_insert=True), referer: http://35.204.127.172/26-th/
[Sun Mar 01 16:00:02.439469 2020] [wsgi:error] [pid 5311:tid 139974376675072] [client 86.52.107.75:54947]   File "/usr/local/lib/python3.5/dist-packages/peewee.py", line 6433, in save, referer: http://35.204.127.172/26-th/
[Sun Mar 01 16:00:02.439472 2020] [wsgi:error] [pid 5311:tid 139974376675072] [client 86.52.107.75:54947]     pk = self.insert(**field_dict).execute(), referer: http://35.204.127.172/26-th/
[Sun Mar 01 16:00:02.439475 2020] [wsgi:error] [pid 5311:tid 139974376675072] [client 86.52.107.75:54947]   File "/usr/local/lib/python3.5/dist-packages/peewee.py", line 1845, in inner, referer: http://35.204.127.172/26-th/
[Sun Mar 01 16:00:02.439478 2020] [wsgi:error] [pid 5311:tid 139974376675072] [client 86.52.107.75:54947]     return method(self, database, *args, **kwargs), referer: http://35.204.127.172/26-th/
[Sun Mar 01 16:00:02.439484 2020] [wsgi:error] [pid 5311:tid 139974376675072] [client 86.52.107.75:54947]   File "/usr/local/lib/python3.5/dist-packages/peewee.py", line 1916, in execute, referer: http://35.204.127.172/26-th/
[Sun Mar 01 16:00:02.439487 2020] [wsgi:error] [pid 5311:tid 139974376675072] [client 86.52.107.75:54947]     return self._execute(database), referer: http://35.204.127.172/26-th/
[Sun Mar 01 16:00:02.439490 2020] [wsgi:error] [pid 5311:tid 139974376675072] [client 86.52.107.75:54947]   File "/usr/local/lib/python3.5/dist-packages/peewee.py", line 2665, in _execute, referer: http://35.204.127.172/26-th/
[Sun Mar 01 16:00:02.439493 2020] [wsgi:error] [pid 5311:tid 139974376675072] [client 86.52.107.75:54947]     return super(Insert, self)._execute(database), referer: http://35.204.127.172/26-th/
[Sun Mar 01 16:00:02.439496 2020] [wsgi:error] [pid 5311:tid 139974376675072] [client 86.52.107.75:54947]   File "/usr/local/lib/python3.5/dist-packages/peewee.py", line 2400, in _execute, referer: http://35.204.127.172/26-th/
[Sun Mar 01 16:00:02.439499 2020] [wsgi:error] [pid 5311:tid 139974376675072] [client 86.52.107.75:54947]     cursor = database.execute(self), referer: http://35.204.127.172/26-th/
[Sun Mar 01 16:00:02.439501 2020] [wsgi:error] [pid 5311:tid 139974376675072] [client 86.52.107.75:54947]   File "/usr/local/lib/python3.5/dist-packages/peewee.py", line 3070, in execute, referer: http://35.204.127.172/26-th/
[Sun Mar 01 16:00:02.439504 2020] [wsgi:error] [pid 5311:tid 139974376675072] [client 86.52.107.75:54947]     return self.execute_sql(sql, params, commit=commit), referer: http://35.204.127.172/26-th/
[Sun Mar 01 16:00:02.439507 2020] [wsgi:error] [pid 5311:tid 139974376675072] [client 86.52.107.75:54947]   File "/usr/local/lib/python3.5/dist-packages/peewee.py", line 3064, in execute_sql, referer: http://35.204.127.172/26-th/
[Sun Mar 01 16:00:02.439510 2020] [wsgi:error] [pid 5311:tid 139974376675072] [client 86.52.107.75:54947]     self.commit(), referer: http://35.204.127.172/26-th/
[Sun Mar 01 16:00:02.439513 2020] [wsgi:error] [pid 5311:tid 139974376675072] [client 86.52.107.75:54947]   File "/usr/local/lib/python3.5/dist-packages/peewee.py", line 2831, in __exit__, referer: http://35.204.127.172/26-th/
[Sun Mar 01 16:00:02.439515 2020] [wsgi:error] [pid 5311:tid 139974376675072] [client 86.52.107.75:54947]     reraise(new_type, new_type(exc_value, *exc_args), traceback), referer: http://35.204.127.172/26-th/
[Sun Mar 01 16:00:02.439518 2020] [wsgi:error] [pid 5311:tid 139974376675072] [client 86.52.107.75:54947]   File "/usr/local/lib/python3.5/dist-packages/peewee.py", line 183, in reraise, referer: http://35.204.127.172/26-th/
[Sun Mar 01 16:00:02.439521 2020] [wsgi:error] [pid 5311:tid 139974376675072] [client 86.52.107.75:54947]     raise value.with_traceback(tb), referer: http://35.204.127.172/26-th/
[Sun Mar 01 16:00:02.439524 2020] [wsgi:error] [pid 5311:tid 139974376675072] [client 86.52.107.75:54947]   File "/usr/local/lib/python3.5/dist-packages/peewee.py", line 3057, in execute_sql, referer: http://35.204.127.172/26-th/
[Sun Mar 01 16:00:02.439527 2020] [wsgi:error] [pid 5311:tid 139974376675072] [client 86.52.107.75:54947]     cursor.execute(sql, params or ()), referer: http://35.204.127.172/26-th/
[Sun Mar 01 16:00:02.439531 2020] [wsgi:error] [pid 5311:tid 139974376675072] [client 86.52.107.75:54947] peewee.OperationalError: unable to open database file, referer: http://35.204.127.172/26-th/
[Sun Mar 01 16:00:02.439547 2020] [wsgi:error] [pid 5311:tid 139974376675072] [client 86.52.107.75:54947] , referer: http://35.204.127.172/26-th/

编辑:通过评论解决

【问题讨论】:

  • 再次检查 SQLite 是否已安装且可用 ($sqlite3)。仔细检查 .prodigy 目录是否已在您的用户主目录中创建并且是可写的。
  • @ThaerA 非常感谢,现在开始工作了。
  • 您能否将您的问题标记为已解决并为自己提供一个答案,以便其他人可以了解具体的操作? (可能跟随@Thaer A cmets,可能更多)
  • @RasmusBaj 很高兴它现在可以工作了。出了什么问题?
  • @ThaerA 我对包含 .db 文件的文件夹有权限问题,这就是整个问题

标签: python apache flask wsgi peewee


【解决方案1】:

由于文件夹权限问题而发生此问题。 这已通过为包含 .db 文件的文件夹提供适当的权限来解决(在这种情况下,应用程序只有读取权限,这就是为什么仅在尝试更改或创建其中的内容时才会出现此问题)这些权限被读取和写。

所以在我的情况下,我使用 chmod 更改了我的 /var/www/FlaskApp/FlaskApp 文件夹(其中包含我所有的烧瓶文件和我的 .db 文件)的权限,这解决了问题

【讨论】: