PIL + Web2py : cannot identify image file

Hi everyone,

After uploading a file via a form, I get the file with

fileitem = request.vars.files.file

store it into the file system

image =, filename)

and then get the size,2)
filesize = fileitem.tell()

Then I need to make some change to it so i do

image_to_transform =

However i get a

File "/usr/local/lib/python2.7/site-packages/PIL/", line 2020, in open
raise IOError("cannot identify image file")
IOError: cannot identify image file

I can see that the files are correctly stored on PA and it also works locally on my computer. I don't understand the problem. Should i open the file with a full path ? I'm a bit lost.

Thank you in advance for your feedback.


┬ĘPS : I import PIL like this :

    from PIL import Image
    import Image


When you say the file works locally, do you mean the file opens in PIL on your local computer?

Also: could you try from a Python console, using an absolute path ('/home/...')

Thanks, Robert

PIL has found the file, so it's not a problem with specifying the path. If it hadn't found the file, you'd get a "no such file or directory" error instead. The issue seems to be that PIL can't identify the file format, which either means the file has become corrupted or it's not the type you think it is, or potentially there's a problem with PIL which is preventing it recognising the image (but I think this is the least likely option currently).

Are you sure the file has uploaded successfully? Try locating the file on the "Files" tab of the dashboard and clicking the download link - check that the image displays successfully in the browser.

Assuming the image does display, what format is it? JPG? PNG?

Also: try copying the file into your static files area, and the accessing it through a web-browser. You can then check to see it's displaying properly.


@Robert : Yes, the web app work correctly on my computer (windows). I've tried from a PA Python Console and use a full path and it worked. With the PIL Library I make a copy and as you said I checked that it was readable through the web interface. So, I have a workaround with this full path but I really do not understand why is not working on PA...

@Cartroo : I've done several tests and indeed the files are correctly uploaded on PA. I downloaded them from the Files tab and everything seems okay, the image displays, the EXIF data are readable. So i assume the files are not corrupted. The fact that i can open those file with PIL in a PA Python console confim a bit more this supposition. I'm uploading JPG file. Because I saw that sometimes PIL can't handle JPG or PNG files, I've tried to upload (and verified that it was not corrupted) a BMP file but i still have the problem.

Weird stuff however : It was working before. I mean before I upgrade web2py to 2.4.6 (the 14th April). After my upgrade i have to make some change to the way I import PIL. I saw PA got some problem with PIL library also. So i guess all of this had some impact on my app but i don't understand which one...

Thanks for your feedbacks, Vincent

Hello vlamoy,

There was a problem with out PIL install as of yesterday. It should be fixed now though. Has this resolved your problem?

I wonder if it could be a bug introduced in the new version of PIL, or perhaps some knock-on effect of the PIL issues seen earlier this week.

First, try reloading your web app and see if the problem persists. Second, would you be willing to provide a link to the image so we can try and reproduce the issue?

EDIT: Bah, beaten to the punch by "Fast Fingers" Hansel... (^_^)

Hi all,

After the webapp reload, the PIL problem have been solved. Thanks to all of you for you help.

Have a good day (or night ^^)