Skip to content
Advertisement

python sqlite3 OperationalError: attempt to write a readonly database

I am trying to run a Flask REST service on CentOS Apache2 using WSGI. The REST service requires a very small storage. So i decided to use SQLite with sqlite3 python package. The whole application worked perfectly well on my local system and on the CentOS server when ran using app.run(). But when i used WSGI to host the application on Apache, i am getting

OperationalError: attempt to write a readonly database

I have checked the permissions of the file. The user and group of the file are set to apache (under which the server is running) using chown andchgrp. Also, the file has rwx permission. Still i am getting read-only database error. Following is what i get by running ls -al on the db file:

-rwxrwxrwx. 1 apache apache 8192 Nov 19 01:39 dbfile.db

My Apache Configuration:

<VirtualHost *>
ServerName wlc.host.com

WSGIDaemonProcess wlcd
WSGIScriptAlias / /var/www/html/wlcd.wsgi
RewriteEngine on
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
<Directory /var/www/html/>
    WSGIProcessGroup wlcd
    WSGIApplicationGroup %{GLOBAL}
    Order deny,allow
    Allow from all
    Require all granted
</Directory>

Advertisement

Answer

In addition to changing the database file permissions, you need also to change permissions for the directory that hosts the database file. You can try the following command:

chmod 664 /path/to/your/directory/

You can also change the directory’s owner as follows:

chown apache:apache /path/to/your/directory/
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement