SQLite错误尝试写入只读数据库

时间:2015-05-27 05:08:57

标签: django apache sqlite mod-wsgi

我一直在努力用Apache和mod_wsgi部署我的django项目。我设法解决了许多问题,但这个问题似乎无法解决。

当我输入地址setakshop.ir:8080时,我的apache日志中出现以下错误:

[Wed May 27 05:54:24 2015] [error] Internal Server Error: /en-gb/
[Wed May 27 05:54:24 2015] [error] Traceback (most recent call last):
[Wed May 27 05:54:24 2015] [error]   File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 87, in get_response
[Wed May 27 05:54:24 2015] [error]     response = middleware_method(request)
[Wed May 27 05:54:24 2015] [error]   File "/usr/local/lib/python2.7/dist-packages/oscar/apps/basket/middleware.py", line 26, in process_request
[Wed May 27 05:54:24 2015] [error]     strategy = selector.strategy(request=request, user=request.user)
[Wed May 27 05:54:24 2015] [error]   File "/usr/local/lib/python2.7/dist-packages/oscar/apps/partner/strategy.py", line 39, in strategy
[Wed May 27 05:54:24 2015] [error]     return Default(request)
[Wed May 27 05:54:24 2015] [error]   File "/usr/local/lib/python2.7/dist-packages/oscar/apps/partner/strategy.py", line 57, in __init__
[Wed May 27 05:54:24 2015] [error]     if request and request.user.is_authenticated():
[Wed May 27 05:54:24 2015] [error]   File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 224, in inner
[Wed May 27 05:54:24 2015] [error]     self._setup()
[Wed May 27 05:54:24 2015] [error]   File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 357, in _setup
[Wed May 27 05:54:24 2015] [error]     self._wrapped = self._setupfunc()
[Wed May 27 05:54:24 2015] [error]   File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/middleware.py", line 22, in <lambda>
[Wed May 27 05:54:24 2015] [error]     request.user = SimpleLazyObject(lambda: get_user(request))
[Wed May 27 05:54:24 2015] [error]   File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/middleware.py", line 10, in get_user
[Wed May 27 05:54:24 2015] [error]     request._cached_user = auth.get_user(request)
[Wed May 27 05:54:24 2015] [error]   File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/__init__.py", line 152, in get_user
[Wed May 27 05:54:24 2015] [error]     user_id = request.session[SESSION_KEY]
[Wed May 27 05:54:24 2015] [error]   File "/usr/local/lib/python2.7/dist-packages/django/contrib/sessions/backends/base.py", line 49, in __getitem__
[Wed May 27 05:54:24 2015] [error]     return self._session[key]
[Wed May 27 05:54:24 2015] [error]   File "/usr/local/lib/python2.7/dist-packages/django/contrib/sessions/backends/base.py", line 175, in _get_session
[Wed May 27 05:54:24 2015] [error]     self._session_cache = self.load()
[Wed May 27 05:54:24 2015] [error]   File "/usr/local/lib/python2.7/dist-packages/django/contrib/sessions/backends/db.py", line 29, in load
[Wed May 27 05:54:24 2015] [error]     self.create()
[Wed May 27 05:54:24 2015] [error]   File "/usr/local/lib/python2.7/dist-packages/django/contrib/sessions/backends/db.py", line 41, in create
[Wed May 27 05:54:24 2015] [error]     self.save(must_create=True)
[Wed May 27 05:54:24 2015] [error]   File "/usr/local/lib/python2.7/dist-packages/django/contrib/sessions/backends/db.py", line 64, in save
[Wed May 27 05:54:24 2015] [error]     obj.save(force_insert=must_create, using=using)
[Wed May 27 05:54:24 2015] [error]   File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py", line 589, in save
[Wed May 27 05:54:24 2015] [error]     force_update=force_update, update_fields=update_fields)
[Wed May 27 05:54:24 2015] [error]   File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py", line 617, in save_base
[Wed May 27 05:54:24 2015] [error]     updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
[Wed May 27 05:54:24 2015] [error]   File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py", line 698, in _save_table
[Wed May 27 05:54:24 2015] [error]     result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
[Wed May 27 05:54:24 2015] [error]   File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py", line 731, in _do_insert
[Wed May 27 05:54:24 2015] [error]     using=using, raw=raw)
[Wed May 27 05:54:24 2015] [error]   File "/usr/local/lib/python2.7/dist-packages/django/db/models/manager.py", line 92, in manager_method
[Wed May 27 05:54:24 2015] [error]     return getattr(self.get_queryset(), name)(*args, **kwargs)
[Wed May 27 05:54:24 2015] [error]   File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 921, in _insert
[Wed May 27 05:54:24 2015] [error]     return query.get_compiler(using=using).execute_sql(return_id)
[Wed May 27 05:54:24 2015] [error]   File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py", line 921, in execute_sql
[Wed May 27 05:54:24 2015] [error]     cursor.execute(sql, params)
[Wed May 27 05:54:24 2015] [error]   File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py", line 65, in execute
[Wed May 27 05:54:24 2015] [error]     return self.cursor.execute(sql, params)
[Wed May 27 05:54:24 2015] [error]   File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 94, in __exit__
[Wed May 27 05:54:24 2015] [error]     six.reraise(dj_exc_type, dj_exc_value, traceback)
[Wed May 27 05:54:24 2015] [error]   File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py", line 65, in execute
[Wed May 27 05:54:24 2015] [error]     return self.cursor.execute(sql, params)
[Wed May 27 05:54:24 2015] [error]   File "/usr/local/lib/python2.7/dist-packages/django/db/backends/sqlite3/base.py", line 485, in execute
[Wed May 27 05:54:24 2015] [error]     return Database.Cursor.execute(self, query, params)
[Wed May 27 05:54:24 2015] [error] OperationalError: attempt to write a readonly database

现在我搜索了这个错误并搜索了很多,我的意思是很多!我知道db.sqlite文件必须具有写权限,它应该由apache(www-data)拥有,包含它的目录也必须具有写权限并且由www-data拥有。我做了这两件事。我没有安装selinux,我已经运行了./manage.py迁移,而且我不知道我还能做些什么来完成这项工作,我甚至还编写了目录和数据库.sqlite文件到777只是看它是否会起作用,但它没有,我知道这不安全。

现在为了您的信息,这是包含db.sqlite文件的文件夹:

-rw-rw-r-- 1 ashkan   ashkan      382 Jan 30 11:54 README.rst
-rw-rw-r-- 1 ashkan   ashkan        0 Jan 30 11:54 __init__.py
drwxrwxr-x 4 ashkan   ashkan     4096 Feb  6 15:15 apps
-rwxrwxrwx 1 www-data www-data 741376 May 27 09:11 db.sqlite
drwxrwxr-x 7 ashkan   ashkan     4096 Jan 30 11:54 deploy
drwxrwxr-x 2 ashkan   ashkan     4096 Jan 30 11:54 fixtures
drwxrwxr-x 2 ashkan   ashkan     4096 Feb 22 00:14 i18n
drwxrwxr-x 3 ashkan   ashkan     4096 Feb 23 21:45 locale
drwxr-xr-x 2 ashkan   ashkan     4096 May 26 08:33 logs
-rwxrwxr-x 1 ashkan   ashkan      242 May 26 00:22 manage.py
lrwxrwxrwx 1 ashkan   ashkan       10 May 25 23:15 oscar -> i18n/oscar
drwxrwxr-x 4 ashkan   ashkan     4096 Jan 30 21:53 public
-rw-rw-r-- 1 ashkan   ashkan    14306 May 26 00:07 settings.py
-rw-r--r-- 1 ashkan   ashkan    10230 May 26 00:23 settings.pyc
-rw-rw-r-- 1 ashkan   ashkan    14876 Feb  6 14:26 settings.py~
-rw-rw-r-- 1 ashkan   ashkan      293 Jan 30 11:54 settings_mysql.py
-rw-rw-r-- 1 ashkan   ashkan      266 May 26 00:16 settings_postgres.py
-rw-rw-r-- 1 ashkan   ashkan      162 Jan 30 11:54 settings_sphinx.py
drwxrwxr-x 2 ashkan   ashkan     4096 Feb 23 21:45 static
drwxrwxr-x 3 ashkan   ashkan     4096 Jan 30 11:54 templates
-rwxrwxr-x 1 ashkan   ashkan     1114 Jan 30 11:54 test_migrations.sh
-rwxrwxr-x 1 ashkan   ashkan     1138 Jan 30 11:54 update_latest.sh
-rw-rw-r-- 1 ashkan   ashkan     1573 Jan 30 11:54 urls.py
-rw-rw-r-- 1 ashkan   ashkan     1427 Jan 30 21:53 urls.pyc
drwxr-xr-x 2 ashkan   ashkan     4096 Jan 30 20:58 whoosh_index
-rw-rw-r-- 1 ashkan   ashkan      778 May 26 00:23 wsgi.py

这是包含db.sqlite文件的目录:

-rw-rw-r--  1 ashkan   ashkan       866 Jan 30 11:54 README.rst
drwxrwxr-x  2 ashkan   ashkan      4096 Jan 30 11:54 _fixtures
-rw-rw-r--  1 ashkan   ashkan    897149 Feb  6 15:34 alaki
-rw-rw-r--  1 ashkan   ashkan   1818857 Feb  6 15:37 alaki.txt
drwxrwxr-x  9 ashkan   ashkan      4096 Jan 30 11:54 demo
-rw-rw-r--  1 ashkan   ashkan    443627 Feb  6 15:34 out
drwxrwxrwx 12 www-data www-data    4096 May 27 09:11 sandbox
drwxrwxr-x  5 ashkan   ashkan      4096 Jan 30 11:54 us

知道造成这个问题的原因是什么?谢谢。

更新1:

这是我的apache配置:

Listen 8080

<VirtualHost *:8080>
    WSGIDaemonProcess setak python-path=/home/ashkan/freshcopy/django-oscar/sites/sandbox:/usr/local/lib/python2.7/site-packages 
    WSGIProcessGroup setak 
    WSGIScriptAlias / /home/ashkan/freshcopy/django-oscar/sites/sandbox/wsgi.py 
    ServerAdmin admin@setakshop.ir 
    ServerName setakshop.ir:8000 
    DocumentRoot /var/www/ 

    Alias /media/ /home/ashkan/freshcopy/django-oscar/sites/sandbox/public/media/ 
    Alias /static/ /home/ashkan/freshcopy/django-oscar/sites/sandbox/public/static/ 

    <Directory /home/ashkan/freshcopy/django-oscar/sites/sandbox>
    <Files wsgi.py>
        Order allow,deny
        allow from all
    </Files>    
    </Directory>    

    <Directory /home/ashkan/freshcopy/django-oscar/sites/sandbox/public/static>
        Order allow,deny
        allow from all
    </Directory>

    <Directory /home/ashkan/freshcopy/django-oscar/sites/sandbox/public/media>
        Order allow,deny
        allow from all
    </Directory>    

    DocumentRoot /var/www
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /var/www/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride None
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel info

    CustomLog ${APACHE_LOG_DIR}/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

</VirtualHost>

更新2:

这是我的wsgi.py:

import os
import sys
import site
import urllib

sys.stdout = sys.stderr

# Project root
root = '/home/ashkan/django-oscar/sites/sandbox'
sys.path.insert(0, root)

# Packages from virtualenv
activate_this = '/home/ashkan/django-oscar/oscar/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))

# Set environmental variable for Django and fire WSGI handler
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
from django.core.wsgi import get_wsgi_application
_application = get_wsgi_application()

def application(environ, start_response):
    environ['PATH_INFO'] = urllib.unquote(environ['REQUEST_URI'].split('?')[0])
    return _application(environ, start_response)

0 个答案:

没有答案