I have an sqlite database using flask_login. The setup works locally, but not on the actual VPS (can still login, but unable to add new users to db)
UPDATE:
after removing the try-catch block I got the actual error:
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) attempt to write a readonly database
I've run the following permissioning, but it still does not work:
chmod 666 users.db
sudo chown www-data /var/www/mywebsite/db/
sudo chown -R www-data: /var/www/mywebsite/db/
the output of getfacl users.db permissions check is:
# file: users.db
# owner: www-data
# group: www-data
user::rw-
group::rw-
other::rw-
UPDATE 2:
I ran these 4 commands and it worked:
sudo chown -R www-data:www-data /var/www/mywebsite/db/
sudo chmod -R u+w /var/www/mywebsite/db/
sudo chmod 666 users.db
sudo chmod 777 db
I think the 777 permissions is a security risk though - but it didn't work with 666. How do I set it without compromising security?
config.py
import configparser
from sqlalchemy import create_engine
config = configparser.ConfigParser()
config.read('config.txt')
engine = create_engine(config.get('database', 'con'))
config.txt
[database]
con = sqlite:///users.db
failing code in auth.py
def add_user(first, last, password, email, engine):
table = user_table()
hashed_password = generate_password_hash(password, method="sha256")
values = dict(first=first, last=last, email=email, password=hashed_password)
statement = table.insert().values(**values)
conn = engine.connect() ## cannot connect here
conn.execute(statement)
conn.close()
return True