permissions

Python module os.chmod(file, 664) does not change the permission to rw-rw-r– but -w–wx—-

Python module os.chmod(file, 664) does not change the permission to rw-rw-r– but -w–wx—- Question: Recently I am using Python module os, when I tried to change the permission of a file, I did not get the expected result. For example, I intended to change the permission to rw-rw-r–, os.chmod(“/tmp/test_file”, 664) The ownership permission is actually …

Total answers: 7

How to set folder permissions in Windows?

How to set folder permissions in Windows? Question: I’m using Python to create a new personal folder when a users AD account is created. The folder is being created but the permissions are not correct. Can Python add the user to the newly created folder and change their permissions? I’m not sure where to begin …

Total answers: 8

Why would shutil.copy() raise a permission exception when cp doesn't?

Why would shutil.copy() raise a permission exception when cp doesn't? Question: shutil.copy() is raising a permissions error: Traceback (most recent call last): File “copy-test.py”, line 3, in <module> shutil.copy(‘src/images/ajax-loader-000000-e3e3e3.gif’, ‘bin/styles/blacktie/images’) File “/usr/lib/python2.7/shutil.py”, line 118, in copy copymode(src, dst) File “/usr/lib/python2.7/shutil.py”, line 91, in copymode os.chmod(dst, mode) OSError: [Errno 1] Operation not permitted: ‘bin/styles/blacktie/images/ajax-loader-000000-e3e3e3.gif’ copy-test.py: import …

Total answers: 6

mysql error : ERROR 1018 (HY000): Can't read dir of '.' (errno: 13)

mysql error : ERROR 1018 (HY000): Can't read dir of '.' (errno: 13) Question: when i try to view the databases in mysql i get this error: ERROR 1018 (HY000): Can’t read dir of ‘.’ (errno: 13) And that stops my app from displaying… My django debugger says: (2002, “Can’t connect to local MySQL server …

Total answers: 6

Django Admin – Giving staff members access to certain areas by default

Django Admin – Giving staff members access to certain areas by default Question: Could anyone tell me how to give staff users in django (those with is_staff set to true) access to some models by default in the admin interface? Currently if I log in as a staff member I just get "You don’t have …

Total answers: 5

Serving large files ( with high loads ) in Django

Serving large files ( with high loads ) in Django Question: I’ve been using a method for serving downloads but since it was not secure i decided to change that . ( the method was a link to the original file in storage , but the risk was that everyone with the link could have …

Total answers: 6

Django – object level premission and class based generic views

Django – object level premission and class based generic views Question: This is the model: class Car(models.Model): user = models.ForeignKey(User, related_name=’cars’) name = models.CharField(max_length=64) Url pattern goes something like this: url(r’^car/(?P<pk>d+)/$’, login_required(CarDetails.as_view()), name=’car_details) And view: class CarDetail(DetailView): context_object_name = ‘car’ template_name = ‘my_app/car_details.html’ model = models.Car def get_object(self, *args, **kwargs): car = super(CarDetail, self).get_object(*args, **kwargs) …

Total answers: 2

Write file with specific permissions in Python

Write file with specific permissions in Python Question: I’m trying to create a file that is only user-readable and -writable (0600). Is the only way to do so by using os.open() as follows? import os fd = os.open(‘/path/to/file’, os.O_WRONLY, 0o600) myFileObject = os.fdopen(fd) myFileObject.write(…) myFileObject.close() Ideally, I’d like to be able to use the with …

Total answers: 6

How to write a custom decorator in django?

How to create a custom decorator in Django? Question: I’m trying to create a custom decorator in Django but I couldn’t find any ways to do it. # "views.py" @custom_decorator def my_view(request): # ……. So, how can I create it in Django? and where should I put it so that I can use it anywhere …

Total answers: 8

How to determine what user and group a Python script is running as?

How to determine what user and group a Python script is running as? Question: I have a CGI script that is getting an “IOError: [Errno 13] Permission denied” error in the stack trace in the web server’s error log. As part of debugging this problem, I’d like to add a little bit of code to …

Total answers: 3