python sqlite3 OperationalError:尝试编写只读数据库 [英] python sqlite3 OperationalError: attempt to write a readonly database

查看:438
本文介绍了python sqlite3 OperationalError:尝试编写只读数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用WSGI在CentOS Apache2上运行Flask REST服务. REST服务需要非常小的存储空间.因此,我决定将SQLite与sqlite3 python包一起使用.使用app.run()运行时,整个应用程序在我的本地系统和CentOS服务器上都运行良好.但是当我使用WSGI在Apache上托管应用程序时,我得到了

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

我已经检查了文件的权限.使用chownchgrp将文件的用户和组设置为apache(在其下运行服务器).此外,该文件具有rwx权限.我仍然收到只读数据库错误.以下是通过在db文件上运行ls -al得到的结果:

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

我的Apache配置:

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>

推荐答案

除了更改数据库文件权限外,还需要更改托管数据库文件的目录的权限.您可以尝试以下命令:

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/

这篇关于python sqlite3 OperationalError:尝试编写只读数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆