tags:

views:

323

answers:

1
from PIL import ImageFile as PILImageFile

p = PILImageFile.Parser()

#Parser the data
for chunk in content.chunks():
    p.feed(chunk)    
try:
    image = p.close()
except IOError:                        
    return None
#Here the model is RGBA
if image.mode != "RGB":
    image = image.convert("RGB")

It always get stuck in here:

image = image.convert("RGB")

File "C:\Python25\Lib\site-packages\PIL\Image.py" in convert
  653.         self.load()
File "C:\Python25\Lib\site-packages\PIL\ImageFile.py" in load
  189.                     s = read(self.decodermaxblock)
File "C:\Python25\Lib\site-packages\PIL\PngImagePlugin.py" in load_read
  365.         return self.fp.read(bytes)
File "C:\Python25\Lib\site-packages\PIL\ImageFile.py" in read
  300.             data = self.data[pos:pos+bytes]

Exception Type: TypeError at 
Exception Value: 'NoneType' object is unsubscriptable
+3  A: 

Looks like the bug described at http://mail.python.org/pipermail/python-list/2008-November/687454.html, and the fix shown at that URL should also work for you.

Alex Martelli
Yes this will work, Thanks
Link is dead... damn
Jiaaro