Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>

like image 707
Shivaprasad Bhat Avatar asked Nov 20 '16 10:11

Shivaprasad Bhat


2 Answers

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/
like image 178
ettanany Avatar answered Nov 18 '22 05:11

ettanany


What worked for me (I don't have sudo) was removing the database file and all migrations and starting again, as described here: How do I delete DB (sqlite3) in Django 1.9 to start from scratch?

like image 2
Matthew Kaye Avatar answered Nov 18 '22 05:11

Matthew Kaye