views:

1057

answers:

2

Hi guys,

I currently have a simple model defined, with a photoupload feature using django thumbnails plugin.

but when i try to upload it gives me the following error:

OSError at /admin/products/photo/add/

(13, 'Permission denied')

Now, i know this is seems to be a permission issue, so the first thing i checked were permissions on the directory and changed these to 777 (Just to Test), restarted the server and fcgi and it still gives the error.

Traceback

Traceback: File "/usr/lib/python2.6/dist-packages/django/core/handlers/base.py" in get_response
  92.                 response = callback(request, *callback_args,
**callback_kwargs) File "/usr/lib/python2.6/dist-packages/django/contrib/admin/options.py" in wrapper
  226.                 return self.admin_site.admin_view(view)(*args,
**kwargs) File "/usr/lib/python2.6/dist-packages/django/views/decorators/cache.py" in _wrapped_view_func
  44.         response = view_func(request, *args, **kwargs) File "/usr/lib/python2.6/dist-packages/django/contrib/admin/sites.py" in inner
  186.             return view(request, *args, **kwargs) File "/usr/lib/python2.6/dist-packages/django/db/transaction.py" in _commit_on_success
  240.                 res = func(*args, **kw) File "/usr/lib/python2.6/dist-packages/django/contrib/admin/options.py" in add_view
  734.                 self.save_model(request, new_object, form, change=False) File "/usr/lib/python2.6/dist-packages/django/contrib/admin/options.py" in save_model
  557.         obj.save() File "/usr/lib/python2.6/dist-packages/django/db/models/base.py" in save
  410.         self.save_base(force_insert=force_insert, force_update=force_update) File "/usr/lib/python2.6/dist-packages/django/db/models/base.py" in save_base
  483.                     values = [(f, f.get_db_prep_save(raw and getattr(self, f.attname) or f.pre_save(self, True))) for f in meta.local_fields if not isinstance(f, AutoField)] File "/usr/lib/python2.6/dist-packages/django/db/models/fields/files.py" in pre_save
  252.             file.save(file.name, file, save=False) File "/var/www/django_projects/gang/../gang/products/thumbs.py" in save
  84.         super(ImageWithThumbsFieldFile, self).save(name, content, save) File "/usr/lib/python2.6/dist-packages/django/db/models/fields/files.py" in save
  91.         self.name = self.storage.save(name, content) File "/usr/lib/python2.6/dist-packages/django/core/files/storage.py" in save
  47.         name = self._save(name, content) File "/usr/lib/python2.6/dist-packages/django/core/files/storage.py" in _save
  146.             os.makedirs(directory) File "/usr/lib/python2.6/os.py" in makedirs
  150.             makedirs(head, mode) File "/usr/lib/python2.6/os.py" in makedirs
  150.             makedirs(head, mode) File "/usr/lib/python2.6/os.py" in makedirs
  150.             makedirs(head, mode) File "/usr/lib/python2.6/os.py" in makedirs
  157.     mkdir(name, mode)

Exception Type: OSError at /admin/products/photo/add/ Exception Value: (13, 'Permission denied')

The user that the FCGI daemon is being run on definitely has access to read and write to that directory.

From settings.py

MEDIA_ROOT = '/var/www/sites/gang/http/media/'
MEDIA_ROOT_URL = '/media/'
+1  A: 

Try checking the permissions on each directory in the path starting at /. Just a thought.

Peter Rowell
Hi peter, this changing permissions of the root dirs seems a bit insecure?
izzy
Uh, I believe I said 'checking', not 'changing' ... big difference. I have seen the following situation: you have your DOCROOT at /a/b/c/d. 'd' is 777 (normally through desperation), 'a', and 'b' are 755 (normal), but 'c' is 700 (or similar) which pretty much ends the party. You keep playing with 'd', but it was 'c' (or whatever) that was the problem.
Peter Rowell
thanks i figured out the problem but your answer helped!
izzy
A: 
mkdir(name, mode)

Exception Type: OSError at /admin/products/photo/add/

but your application is deployed at

/var/www/django_projects/gangr/../gangr/

Do you have a directory path set to an absolute path "/admin/products/photo/add/" rather than something relative like "admin/products/photo/add/"?

Check the MEDIA_ROOT and MEDIA_URL in your settings.py file.

http://docs.djangoproject.com/en/dev/ref/settings/#media-root

John Mee
hi my application is actually deployed at:/var/www/django_projects/gangr/products/ Dont know why it's saying /.../gangrHowever i do have a MEDIA_ROOT setup (which points to the http used by lightttpd i.e '.../http/media', and MEDIA_ROOT_URL which is '/media/'
izzy
I have updated the question with my settings.py info
izzy