关于python 3.x:Errno 13权限被拒绝:’。cache’django app?

Errno 13 Permission Denied: '.cache' django app?

我正在Ubuntu Server 14.04上部署一个django应用程序,我已经成功地在我的浏览器中找到了IP地址。 但是,现在我得到一个标记为django的调试错误

[Errno 13] Permission Denied: '.cache'

我不太确定这意味着什么。 应用程序遇到的路径是

1
/usr/lib/python3.4/os.py

这对我来说似乎很奇怪,因为我正在使用一个不在该目录下的虚拟环境来建立python版本和依赖项。

我意识到很多人都有同样的问题,但我没有找到一个好的解决方案。 我不是在寻找一个只允许某个目录的所有权限的解决方案; 我想在应用此修复程序时保持良好的安全级别。 提前致谢。

来自error.log:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
[Wed May 18 20:42:24.836874 2016] [:error] [pid 6078:tid 139663218018048] Traceback (most recent call last):
[Wed May 18 20:42:24.836879 2016] [:error] [pid 6078:tid 139663218018048]   File"/home/openflow/.virtualenvs/sched_app.v0.2/lib/python3.4/site-packages/django/core/handlers/base.py", line 123, in get_response
[Wed May 18 20:42:24.836883 2016] [:error] [pid 6078:tid 139663218018048]     response = middleware_method(request)
[Wed May 18 20:42:24.836886 2016] [:error] [pid 6078:tid 139663218018048]   File"/home/openflow/.virtualenvs/sched_app.v0.2/lib/python3.4/site-packages/django/middleware/common.py", line 61, in process_request
[Wed May 18 20:42:24.836890 2016] [:error] [pid 6078:tid 139663218018048]     if self.should_redirect_with_slash(request):
[Wed May 18 20:42:24.836894 2016] [:error] [pid 6078:tid 139663218018048]   File"/home/openflow/.virtualenvs/sched_app.v0.2/lib/python3.4/site-packages/django/middleware/common.py", line 79, in should_redirect_with_slash
[Wed May 18 20:42:24.836898 2016] [:error] [pid 6078:tid 139663218018048]     not urlresolvers.is_valid_path(request.path_info, urlconf)
[Wed May 18 20:42:24.836901 2016] [:error] [pid 6078:tid 139663218018048]   File"/home/openflow/.virtualenvs/sched_app.v0.2/lib/python3.4/site-packages/django/core/urlresolvers.py", line 668, in is_valid_path
[Wed May 18 20:42:24.836905 2016] [:error] [pid 6078:tid 139663218018048]     resolve(path, urlconf)
[Wed May 18 20:42:24.836908 2016] [:error] [pid 6078:tid 139663218018048]   File"/home/openflow/.virtualenvs/sched_app.v0.2/lib/python3.4/site-packages/django/core/urlresolvers.py", line 534, in resolve
[Wed May 18 20:42:24.836912 2016] [:error] [pid 6078:tid 139663218018048]     return get_resolver(urlconf).resolve(path)
[Wed May 18 20:42:24.836915 2016] [:error] [pid 6078:tid 139663218018048]   File"/home/openflow/.virtualenvs/sched_app.v0.2/lib/python3.4/site-packages/django/core/urlresolvers.py", line 374, in resolve
[Wed May 18 20:42:24.836919 2016] [:error] [pid 6078:tid 139663218018048]     for pattern in self.url_patterns:
[Wed May 18 20:42:24.836922 2016] [:error] [pid 6078:tid 139663218018048]   File"/home/openflow/.virtualenvs/sched_app.v0.2/lib/python3.4/site-packages/django/utils/functional.py", line 33, in __get__
[Wed May 18 20:42:24.836939 2016] [:error] [pid 6078:tid 139663218018048]     res = instance.__dict__[self.name] = self.func(instance)
[Wed May 18 20:42:24.836944 2016] [:error] [pid 6078:tid 139663218018048]   File"/home/openflow/.virtualenvs/sched_app.v0.2/lib/python3.4/site-packages/django/core/urlresolvers.py", line 417, in url_patterns
[Wed May 18 20:42:24.836947 2016] [:error] [pid 6078:tid 139663218018048]     patterns = getattr(self.urlconf_module,"urlpatterns", self.urlconf_module)
[Wed May 18 20:42:24.836951 2016] [:error] [pid 6078:tid 139663218018048]   File"/home/openflow/.virtualenvs/sched_app.v0.2/lib/python3.4/site-packages/django/utils/functional.py", line 33, in __get__
[Wed May 18 20:42:24.836954 2016] [:error] [pid 6078:tid 139663218018048]     res = instance.__dict__[self.name] = self.func(instance)
[Wed May 18 20:42:24.836958 2016] [:error] [pid 6078:tid 139663218018048]   File"/home/openflow/.virtualenvs/sched_app.v0.2/lib/python3.4/site-packages/django/core/urlresolvers.py", line 410, in urlconf_module
[Wed May 18 20:42:24.836962 2016] [:error] [pid 6078:tid 139663218018048]     return import_module(self.urlconf_name)
[Wed May 18 20:42:24.836965 2016] [:error] [pid 6078:tid 139663218018048]   File"/usr/lib/python3.4/importlib/__init__.py", line 109, in import_module
[Wed May 18 20:42:24.836968 2016] [:error] [pid 6078:tid 139663218018048]     return _bootstrap._gcd_import(name[level:], package, level)
[Wed May 18 20:42:24.836972 2016] [:error] [pid 6078:tid 139663218018048]   File"<frozen importlib._bootstrap>", line 2254, in _gcd_import
[Wed May 18 20:42:24.836975 2016] [:error] [pid 6078:tid 139663218018048]   File"<frozen importlib._bootstrap>", line 2237, in _find_and_load
[Wed May 18 20:42:24.836978 2016] [:error] [pid 6078:tid 139663218018048]   File"<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
[Wed May 18 20:42:24.836982 2016] [:error] [pid 6078:tid 139663218018048]   File"<frozen importlib._bootstrap>", line 1200, in _load_unlocked
[Wed May 18 20:42:24.836985 2016] [:error] [pid 6078:tid 139663218018048]   File"<frozen importlib._bootstrap>", line 1129, in _exec
[Wed May 18 20:42:24.836988 2016] [:error] [pid 6078:tid 139663218018048]   File"<frozen importlib._bootstrap>", line 1471, in exec_module
[Wed May 18 20:42:24.836991 2016] [:error] [pid 6078:tid 139663218018048]   File"<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
[Wed May 18 20:42:24.836995 2016] [:error] [pid 6078:tid 139663218018048]   File"var/www/html/scheduler.marist.edu/sched_app/sched_site/urls.py", line 20, in <module>
[Wed May 18 20:42:24.836998 2016] [:error] [pid 6078:tid 139663218018048]     url(r'^sched_app/', include('sched_app.urls')),
[Wed May 18 20:42:24.837002 2016] [:error] [pid 6078:tid 139663218018048]   File"/home/openflow/.virtualenvs/sched_app.v0.2/lib/python3.4/site-packages/django/conf/urls/__init__.py", line 52, in include
[Wed May 18 20:42:24.837005 2016] [:error] [pid 6078:tid 139663218018048]     urlconf_module = import_module(urlconf_module)
[Wed May 18 20:42:24.837009 2016] [:error] [pid 6078:tid 139663218018048]   File"/usr/lib/python3.4/importlib/__init__.py", line 109, in import_module
[Wed May 18 20:42:24.837012 2016] [:error] [pid 6078:tid 139663218018048]     return _bootstrap._gcd_import(name[level:], package, level)
[Wed May 18 20:42:24.837015 2016] [:error] [pid 6078:tid 139663218018048]   File"<frozen importlib._bootstrap>", line 2254, in _gcd_import
[Wed May 18 20:42:24.837018 2016] [:error] [pid 6078:tid 139663218018048]   File"<frozen importlib._bootstrap>", line 2237, in _find_and_load
[Wed May 18 20:42:24.837022 2016] [:error] [pid 6078:tid 139663218018048]   File"<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
[Wed May 18 20:42:24.837025 2016] [:error] [pid 6078:tid 139663218018048]   File"<frozen importlib._bootstrap>", line 1200, in _load_unlocked
[Wed May 18 20:42:24.837028 2016] [:error] [pid 6078:tid 139663218018048]   File"<frozen importlib._bootstrap>", line 1129, in _exec
[Wed May 18 20:42:24.837036 2016] [:error] [pid 6078:tid 139663218018048]   File"<frozen importlib._bootstrap>", line 1471, in exec_module
[Wed May 18 20:42:24.837040 2016] [:error] [pid 6078:tid 139663218018048]   File"<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
[Wed May 18 20:42:24.837043 2016] [:error] [pid 6078:tid 139663218018048]   File"var/www/html/scheduler.marist.edu/sched_app/sched_app/urls.py", line 2, in <module>
[Wed May 18 20:42:24.837047 2016] [:error] [pid 6078:tid 139663218018048]     from . import views
[Wed May 18 20:42:24.837050 2016] [:error] [pid 6078:tid 139663218018048]   File"var/www/html/scheduler.marist.edu/sched_app/sched_app/views.py", line 131, in <module>
[Wed May 18 20:42:24.837054 2016] [:error] [pid 6078:tid 139663218018048]     h = httplib2.Http(".cache")
[Wed May 18 20:42:24.837057 2016] [:error] [pid 6078:tid 139663218018048]   File"/home/openflow/.virtualenvs/sched_app.v0.2/lib/python3.4/site-packages/httplib2/__init__.py", line 907, in __init__
[Wed May 18 20:42:24.837060 2016] [:error] [pid 6078:tid 139663218018048]     self.cache = FileCache(cache)
[Wed May 18 20:42:24.837064 2016] [:error] [pid 6078:tid 139663218018048]   File"/home/openflow/.virtualenvs/sched_app.v0.2/lib/python3.4/site-packages/httplib2/__init__.py", line 675, in __init__
[Wed May 18 20:42:24.837067 2016] [:error] [pid 6078:tid 139663218018048]     os.makedirs(self.cache)
[Wed May 18 20:42:24.837071 2016] [:error] [pid 6078:tid 139663218018048]   File"/usr/lib/python3.4/os.py", line 237, in makedirs
[Wed May 18 20:42:24.837074 2016] [:error] [pid 6078:tid 139663218018048]     mkdir(name, mode)
[Wed May 18 20:42:24.837079 2016] [:error] [pid 6078:tid 139663218018048] PermissionError: [Errno 13] Permission denied: '.cache'


这是你的错误:

1
2
  File"var/www/html/scheduler.marist.edu/sched_app/sched_app/views.py", line 131, in
    [Wed May 18 20:42:24.837054 2016] [:error] [pid 6078:tid 139663218018048]     h = httplib2.Http(".cache")

这与django缓存无关,因为我(可能几乎所有读过此内容的人)都认为。 这与你使用httplib2有关。

注释掉那段代码,你就可以启动了。

更新。 我不是httplib2的专家,但我刚才读到的是".cache"意味着httplib2将缓存它将检索的页面的目录。 如果您没有传递该参数,它将不会缓存任何内容。 如果要启用缓存,可能需要在此处使用安全但可写的路径。