Python Script Cannot Write to Directory
News123
news1234 at free.fr
Wed Aug 4 03:21:20 EDT 2010
On 08/04/2010 06:01 AM, Chris Brauchli wrote:
> Hi,
>
> I am writing a script that, at one point, copies a file from directory
> A to directory B. Directory B can only be written to by root, but the
> script is always called with sudo, so this shouldn't be an issue, but
> it is. I have tried using shutil.copy() and calling "sudo cp " with
> os.popen to no avail. I cannot get the script to copy a file to
> directory B. The strange thing is if I run the python interpreter (as
> sudo) and type in shutil.copy it works. It also works if I try to copy
> the file to a less protected directory. It only happens when I try to
> copy a file to directory B from a python script.
>
> Any ideas why this is happening? If more information is needed or
> something isn't clear let me know. Thanks for helping.
>
a fiew suggestions suggestions:
1,) open a terminal window with sudo -s and make ALL of the following
tests from this window.
2.) tell use the exact permissions of your destination directory
ls -ld DESTINATION_DIRECTORY
3.) verify, whether the file you want to copy exists already in the
destination directory
ls -l DESTINATION_DIRECTORY/DSTNTN_FILE_NAME
3.) try following python
import os
print os.getcwd()
import shutil
shutil("YOUR_SOURCE_FILE_NAME","DESTINATION_DIRECTORY/DSTNTN_FILE_NAME")
4.) try the same from a shell window
cp YOUR_SOURCE_FILE_NAME DESTINATION_DIRECTORY/DSTNTN_FILE_NAME
More information about the Python-list
mailing list