Windows - Image.save() - IOError: [Errno 13] Permission denied #494

Closed
Dooque opened this Issue Jan 18, 2014 · 6 comments

Comments

Projects
None yet
4 participants

Dooque commented Jan 18, 2014

Hello.

Problem:
When I try to save an opened Image object to a file that was previously created by Image.new() and saved, I have a permission denied error.

Steps to reproduce:
Environment:
Windows 7 (64-bits)
Python 2.7.3
Pillow 2.3.0

Execute the following code

from PIL import Image
img1 = Image.new('I;16', (10, 10))
img1.save('test.tiff', 'TIFF')
img2 = Image.open('test.tiff')
img2.save('test.tiff')

you should see this error

C:\Python27\lib\site-packages\PIL\Image.py
   1458         if isPath(fp):
-> 1459             fp = builtins.open(fp, "wb")
   1560             close = 1
   1461         else:

IOError: [Errno 13] Permission denied: 'test.tiff'

Expected behavior:
It should save the image file, no matter how many references to that file I have.

Of course, I have permission to read/write the file inside the directory I am.
I executed it as Admin, I tried to change the mode from the line 1459 to "r+b", and the error is the same.

NOTE: On Ubuntu 12.04 LTS (same python and pillow versions) this code works well.

Thanks.

Dooque commented Jan 19, 2014

Hello.

I was trying to figure out the problem and I found a possible solution, at least it works for me:

Index: tags/2.3.0/PIL/Image.py
===================================================================
--- tags/2.3.0/PIL/Image.py (revision 1344)
+++ tags/2.3.0/PIL/Image.py (working copy)
@@ -1990,7 +1990,7 @@

     if isPath(fp):
         filename = fp
-        fp = builtins.open(fp, "rb")
+        fp = builtins.open(fp, "r+b")
     else:
         filename = ""

Regards.

Owner

aclark4life commented Mar 17, 2014

I'm not sure I understand the syntax change… @wiredfool ?

@aclark4life aclark4life added the bug label Mar 17, 2014

@aclark4life aclark4life added this to the Future milestone Mar 17, 2014

Owner

wiredfool commented Mar 17, 2014

rb is open readonly + binary, r+b is read/write (aka update), binary.

I'm very -1 on setting Image.open to use overwrite mode. I think what's happening in the initial case is that image.tiff is still open, preventing the save. This almost sounds like #526, now that I look more closely.

Owner

aclark4life commented Mar 17, 2014

Possible duplicate of #526

Dooque commented Mar 17, 2014

Yes, that's the problem, thanks.

when i use it , i only use the pathname, it needs a filename

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment