When I upload a PNG file and use PIL to handle it,there will be an error occured: 'NoneType' object is unsubscriptable
I do not know why and other formats(BMP GIF JPG JPEG) are all ok. The following is my code in my views.py: f = request.FILES["imagefile"] fileExt = (f.name).split(".")[-1].lower() #get the pic's extension parser = ImageFile.Parser() for chunk in f.chunks(): parser.feed(chunk) img = parser.close() img.save("test"+"."+fileExt) The detail of the occured error is as follows: Environment: Request Method: POST Request URL: http://localhost:8000/photos/album/2/upload/ Django Version: 1.0-final-SVN-unknown Python Version: 2.5.2 Installed Applications: ['django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.admin', ] Installed Middleware: ('django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware') Traceback: File "F:\Python25\Lib\site-packages\django\core\handlers\base.py" in get_response 86. response = callback(request, *callback_args, **callback_kwargs) File "F:\52trips\wawafish\..\wawafish\photos\views.py" in upload_photo 175. img.save("test"+"."+fileExt) File "F:\Python25\Lib\site-packages\PIL\Image.py" in save 1372. self.load() File "F:\Python25\Lib\site-packages\PIL\ImageFile.py" in load 189. s = read(self.decodermaxblock) File "F:\Python25\Lib\site-packages\PIL\PngImagePlugin.py" in load_read 365. return self.fp.read(bytes) File "F:\Python25\Lib\site-packages\PIL\ImageFile.py" in read 300. data = self.data[pos:pos+bytes] Exception Type: TypeError at /photos/album/2/upload/ Exception Value: 'NoneType' object is unsubscriptable --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---