0

I am trying to copy files from one user's home directory to another user's home directory in PYTHON. Problem is I get access denied due to the user permissions. Is there a way to elevate the permissions in linux for the PYTHON user?

I tried copying files using distutils.file_util.copy_file() and shutil.copyfile() but I get: [Errno 13] Permission denied: '/home/testuser/test.txt' any ideas?

Walt
  • 1,521
  • 2
  • 13
  • 29

1 Answers1

0

There is no PYTHON user, your Python process will be run with the permissions of the user who executed the script. If you need to run your script with different permissions use sudo to run the script as root or some other user that has read permission on the source directory and write permission on the destination.

Andrew Clark
  • 202,379
  • 35
  • 273
  • 306
  • I was hoping there was a way to designate the permissions inside the script. – Walt Feb 15 '12 at 20:50
  • The answers to [this question](http://stackoverflow.com/q/1970329/505154) seem to indicate that there isn't a good way to do that, however you could execute the copy command using the [subprocess](http://docs.python.org/library/subprocess.html#module-subprocess) module and use sudo there to elevate permissions. – Andrew Clark Feb 15 '12 at 20:52
  • Ended up doing what you suggested. Thanks for your response. – Walt Feb 16 '12 at 02:30