[Tutor] Permissions Error

Michael Lewis mjolewis at gmail.com
Tue Mar 27 06:00:58 CEST 2012


>
> Message: 1
> Date: Mon, 26 Mar 2012 10:52:19 +1100
> From: Steven D'Aprano <steve at pearwood.info>
> To: tutor at python.org
> Subject: Re: [Tutor] Permissions Error
> Message-ID: <4F6FAFB3.4060301 at pearwood.info>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> Michael Lewis wrote:
> > Hi everyone,
> >
> > If I've created a folder, why would I receive a permissions error when
> > trying to copy the file. My source code is here:
> > http://pastebin.com/1iX7pGDw
>
> The usual answer to "why would I receive a permissions error" is that you
> don't actually have permission to access the file.
>
> What is the actual error you get?
>

Traceback (most recent call last):
  File "C:\Python27\Utilities\copyfiles.py", line 47, in <module>
    copyfiles(srcdir, dstdir)
  File "C:\Python27\Utilities\copyfiles.py", line 42, in copyfiles
    shutil.copy(srcfile, dstfile)
  File "C:\Python27\lib\shutil.py", line 116, in copy
    copyfile(src, dst)
  File "C:\Python27\lib\shutil.py", line 81, in copyfile
    with open(src, 'rb') as fsrc:
IOError: [Errno 13] Permission denied: 'C:\\Users\\Chief
Ninja\\Pictures\\testdir'

I've noticed that the code runs if I use shutil.copyfiles instead of
shutil.copy. Do you know why?

I've also noticed that if I have a sub-directory, I receive a permission
error. However, if I use os.walk, then my code runs if I have a
sub-directory in my source directory. My problem then becomes that os.walk
doesn't actually move the directory, but instead just moves the files
within the sub-directory. Oddly, this code runs without permission error
when I use shutil.copy unlike the above piece which raises an error when I
use shutil.copy. However, if I use shutil.copyfile, I get the below error:
(Do you know why?)

Traceback (most recent call last):
  File "C:/Python27/Homework/oswalk.py", line 41, in <module>
    copyfiles(srcdir, dstdir)
  File "C:/Python27/Homework/oswalk.py", line 36, in copyfiles
    shutil.copyfile(srcfile, dstdir)
  File "C:\Python27\lib\shutil.py", line 82, in copyfile
    with open(dst, 'wb') as fdst:
IOError: [Errno 13] Permission denied: 'C:\\newtest'

The code where I use os.walk is here:
http://pastebin.com/1hchnmM1


>
> > When I check the properties/security of the file in question, the system
> > says I have full control.
>
> This does not sound like a Python problem, but an operating system problem.
> What OS are you using?
>

I am using Windows XP

>
> You should check the permissions on the folder, not just the file. Also, if
> you OS supports it, check any extended permissions and ACLs that might
> apply.
> Can you copy the file using another language, e.g. using powershell, bash
> or
> applescript? Also check that you are running the Python script as the same
> user you used when creating the file.
>

I've checked the permissions on the folder and I have full control. I
haven't yet checked extended permissions and ACL's etc, but will do so.

Thanks!

>
>
>
> --
> Steven
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120326/54ad6bf4/attachment.html>


More information about the Tutor mailing list