简体   繁体   中英

Apache running Flask on gcloud 500 Internal Server Error

I have been trying to deploy my flask app on an apache web sever and have gotten it to somewhat function. I am now facing the issue that the only page on which I need to either create a new entry in my database (using peewee sqlite for all things database related) or make changes to an already exciting entry I receive the 500 Internal Server Error.

It seems to be fully functional when reading the database, but unable to write to it. I have updated the .db files permissions to be 777, but that did not help.

The following code is in the Flask file and declares the path to the .db file:

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')

I have placed the latest error log below, it occurred when trying to create a new entry, any ideas are much appreciated.

[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/

EDIT: Solved by comment

The issue was occurring due to folder permissions issue. This was resolved by giving the proper permissions to the folder containing the .db file (in this case the application only had read permissions, that is why this issue was only occurring when trying to change or create content in it) these permissions being read and write.

So in my case I used chmod to change the permissions of my /var/www/FlaskApp/FlaskApp folder (which contains all my flask files and my .db file) and this resolved the issue

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM