Apache 运行 gcloud 上的 Flask 500 内部服务器错误

Apache running Flask on gcloud 500 Internal Server Error

我一直在尝试将我的 flask 应用程序部署到 apache 网络服务器上,并使其能够正常运行。 我现在面临的问题是,我需要在我的数据库中创建一个新条目(使用 peewee sqlite 处理与数据库相关的所有内容)或更改已经令人兴奋的条目的唯一页面我收到 500 内部服务器错误。

读数据库时似乎功能齐全,但无法写入。我已将 .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/

编辑:通过评论解决

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

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