python sqlite3 OperationalError: attempt to write a readonly database

只愿长相守 提交于 2020-02-21 10:00:33

问题


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>


回答1:


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/



回答2:


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?



来源:https://stackoverflow.com/questions/40703228/python-sqlite3-operationalerror-attempt-to-write-a-readonly-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!