From b95199aa73d255478ed55852dcd9e7ac823b697b Mon Sep 17 00:00:00 2001 From: Tyler Date: Sun, 22 Jan 2023 00:27:06 -0800 Subject: [PATCH] bugfix: installation permissions error for sqlite writing --- README.txt | 4 ++++ app.py | 11 +++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/README.txt b/README.txt index 69a55dd..128573a 100644 --- a/README.txt +++ b/README.txt @@ -28,6 +28,10 @@ or by executing kjv-api-test.sh which will listen on 0.0.0.0:1612 Visiting the base directory will show the user-facing documentation via web browser or cURL. +When testing or doing a deployment, the data directory must be owned by whatever user is +running the program in order to prevent a sqlite3.OperationalError for writing to a "readonly" +database. + CONTENTS ======== . diff --git a/app.py b/app.py index 9e9f7b5..4caae25 100644 --- a/app.py +++ b/app.py @@ -520,11 +520,14 @@ def sequential_read(start=0, num=1, uid=None, getuid=False): start = verse_ids.index(int(show(kw=start, get_start_verse_id=True))) uid = str(uuid.uuid4()) - seq_cur.execute( - "INSERT INTO reading_tracker VALUES('{}', {}, '{}')".format( - uid, start, last_used + try: + seq_cur.execute( + "INSERT INTO reading_tracker VALUES('{}', {}, '{}')".format( + uid, start, last_used + ) ) - ) + except sqlite3.OperationalError: + return jsonify({"error":"Something went wrong with the database. Check permissions?"}) seq_conn.commit() dbg2("Created new UID: {}".format(uid)) return "Your new UID is: {}".format(uid)