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
1 个解决方案
#1
This results from an incorrect coding of close within PIL, its a bug.
这是因为PIL中关闭的错误编码,这是一个错误。
Edit the File ( path may be different on your system ):
编辑文件(系统上的路径可能不同):
sudo vi /usr/lib64/python2.6/site-packages/PIL/ImageFile.py
sudo vi /usr/lib64/python2.6/site-packages/PIL/ImageFile.py
Online 283 Modify:
在线283修改:
def close(self):
self.data = self.offset = None
Change it to:
将其更改为:
def close(self):
#self.data = self.offset = None
self.offset = None
Thats it, comment out the broken code, add the correct line, and save the file. All done, just run the program that was failing before and it will work now.
多数民众赞成,注释掉损坏的代码,添加正确的行,并保存文件。一切都完成了,只需运行之前失败的程序,它现在就可以运行了。
#1
This results from an incorrect coding of close within PIL, its a bug.
这是因为PIL中关闭的错误编码,这是一个错误。
Edit the File ( path may be different on your system ):
编辑文件(系统上的路径可能不同):
sudo vi /usr/lib64/python2.6/site-packages/PIL/ImageFile.py
sudo vi /usr/lib64/python2.6/site-packages/PIL/ImageFile.py
Online 283 Modify:
在线283修改:
def close(self):
self.data = self.offset = None
Change it to:
将其更改为:
def close(self):
#self.data = self.offset = None
self.offset = None
Thats it, comment out the broken code, add the correct line, and save the file. All done, just run the program that was failing before and it will work now.
多数民众赞成,注释掉损坏的代码,添加正确的行,并保存文件。一切都完成了,只需运行之前失败的程序,它现在就可以运行了。