Issue
I am deploying a django app on Ubuntu Server 14.04 and I have successfully been able to get to the IP address in my browser. However, now I am getting a django debug error which is labeled:
[Errno 13] Permission Denied: '.cache'
I am not really sure what this means. The path that the app is getting choke on is:
/usr/lib/python3.4/os.py
which seems weird to me because I am using a virtual environment, that is not under that directory, to establish the python version, and dependencies.
I realize that a lot of people have had the same problem, but I haven't found a single good solution to this. I am not looking for a solution that just allows all permissions for a certain directory; I would like to maintain a good level of security when applying this fix.
From error.log
:
[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'
Solution
Here's your error:
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")
This has nothing to do with django caching as I (and probably almost everyone else who read this) supposed. It's to do with your use of httplib2
.
Comment out that section of code and you will be able to start up.
Update. I am not an expert on httplib2 but what I just read is that ".cache" implies the directory where httplib2 will cache pages that it will retrieve. If you don't pass that parameter it will not cache anything. You might want to use a safe but writable path here if you want to enable caching.
Answered By - e4c5 Answer Checked By - Candace Johnson (WPSolving Volunteer)