Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OSError: [Error 1] Operation not permitted

I am trying to run a python script which uses a binary file (xFiles.bin.addr_patched) created by a postlinker. However, I am getting this error.

File "abc.py", line 74, in ParseCmd
shutil.copy(gOptions.inputX, gWorkingXFile)
File "/usr/lib/python2.6/shutil.py", line 89, in copy
copymode(src, dst)
File "/usr/lib/python2.6/shutil.py", line 66, in copymode
os.chmod(dst, mode)

OSError: [Errno 1] Operation not permitted: 'myPath/xFiles.bin.addr_patched'

When I checked the permissions of this xFiles.bin, by ls-l, it shows that

-rwxrwxrwx 1 nobody  nogroup 

I presume the error is because this file was created by some other application, the python script I am running does not have access to it. Since I am beginner wrt ubuntu, I don't really know how to fix it. Any suggestions on how to fix this?

SOLVED:

As one of the answers Suggested : chown username:groupname file name fixes this issue

like image 519
user1357576 Avatar asked Jun 07 '12 18:06

user1357576


4 Answers

You could try (from the command line, but I'm sure there's a syntax in python):

sudo chown your_username:your_groupname filename

Note: The group is usually just your username. I feel like there's something wrong with those permissions though. Read Write Execute for everyone seems to be off. How was this file created? How did it get to be created by the user nobody?

like image 66
Linuxios Avatar answered Oct 30 '22 15:10

Linuxios


Python code to change the permission:

from getpwnam import pwd
from getgrnam import grp
import os

uid = getpwnam("YOUR_USERNAME")[2]
gid = grp.getgrnam("YOUR_GROUPNAME")[2]
os.chown("myPath/xFiles.bin.addr_patched", uid, gid)

Run the script with sudo and you're done.

like image 36
Fatih Arslan Avatar answered Oct 30 '22 14:10

Fatih Arslan


My guess is that you should be looking at the permissions for myPath folder instead. Seems like you can't write to it, hence the problem. Try ls -l myPath/.. and see the permissions for myPath. If that's the problem, change the permissions on the folder with chmod.

P.S. Also, see Google top result on Linux file permissions.

like image 1
Lev Levitsky Avatar answered Oct 30 '22 13:10

Lev Levitsky


I had this problem when running a python script on my mac (10.14 Mojave) trying to access /Users/xxx/Pictures/Photos Library.photoslibrary. The full solution can be found in http://osxdaily.com/2018/10/09/fix-operation-not-permitted-terminal-error-macos/

Summary: Go to System Preferences > Security & Privacy > Privacy > Full Disk Access and add your IDE or python interpreter to the list.

like image 1
Federico Avatar answered Oct 30 '22 13:10

Federico