在Django中获取无效的图像错误,但PIL已安装并通过所有测试 [英] Getting invalid image error in Django, but PIL is installed and passes all tests

查看:404
本文介绍了在Django中获取无效的图像错误,但PIL已安装并通过所有测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我终于通过Django(开发版本)和Python 2.6安装在/opt/python2.6上,在RHEL5上成功安装了PIL(经历了许多困难)。

So I've finally successfully installed PIL (after many difficulties) on RHEL5 with Django (development version) and Python 2.6 installed at /opt/python2.6.

运行selftest.py显示所有内容似乎都正确安装:

Running selftest.py shows that everything appears to be installed correctly:

$ python2.6 selftest.py 
57 tests passed.

我可以毫不费力地上传.png文件和.gif文件,但在尝试上传时遇到问题.jpg文件使用ImageField:上传有效的图像。您上传的文件不是图像或损坏的图像。

I can upload .png files and .gif files without difficulties, but run into problems when trying to upload .jpg files using the ImageField: "Upload a valid image. The file you uploaded was either not an image or a corrupted image."

我看到这个其他问题,并运行测试,看PIL是否会验证图像,它做了:

I saw this other question and ran the test to see if PIL would verify the image, and it did:

>>> from PIL import Image
>>> trial_image=Image.open("/tmp/jordanthecoder.jpg")
>>> trial_image.verify()
>>> 

可能发生什么事?显然,允许JPEG是很重要的。我意识到一个选择是使用FileField,然后检查以确保它是GIF,PNG或JPEG之一,但我宁愿使用内置对象。

What could be going on? Obviously, allowing JPEG is kind of important. I realize one option is to use a FileField instead and then check to make sure it is one of GIF, PNG, or JPEG, but I'd much rather use the built-in object.

如果这是有帮助的,这里是上面的shell的详细显示:

In case this is helpful, here is the verbose display for the shell above:

$ python2.6 -v
Python 2.6.4 (r264:75706, Jan 15 2010, 14:42:33) 
[GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
dlopen("/opt/python2.6/lib/python2.6/lib-dynload/readline.so", 2);
import readline # dynamically loaded from /opt/python2.6/lib/python2.6/lib-dynload/readline.so
>>> from PIL import Image
import PIL # directory /opt/python2.6/lib/python2.6/site-packages/PIL
# /opt/python2.6/lib/python2.6/site-packages/PIL/__init__.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/__init__.py
import PIL # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/__init__.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/Image.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/Image.py
import PIL.Image # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/Image.pyc
# /opt/python2.6/lib/python2.6/lib-tk/FixTk.pyc matches /opt/python2.6/lib/python2.6/lib-tk/FixTk.py
import FixTk # precompiled from /opt/python2.6/lib/python2.6/lib-tk/FixTk.pyc
import ctypes # directory /opt/python2.6/lib/python2.6/ctypes
# /opt/python2.6/lib/python2.6/ctypes/__init__.pyc matches /opt/python2.6/lib/python2.6/ctypes/__init__.py
import ctypes # precompiled from /opt/python2.6/lib/python2.6/ctypes/__init__.pyc
dlopen("/opt/python2.6/lib/python2.6/lib-dynload/_ctypes.so", 2);
import _ctypes # dynamically loaded from /opt/python2.6/lib/python2.6/lib-dynload/_ctypes.so
# /opt/python2.6/lib/python2.6/struct.pyc matches /opt/python2.6/lib/python2.6/struct.py
import struct # precompiled from /opt/python2.6/lib/python2.6/struct.pyc
dlopen("/opt/python2.6/lib/python2.6/lib-dynload/_struct.so", 2);
import _struct # dynamically loaded from /opt/python2.6/lib/python2.6/lib-dynload/_struct.so
# /opt/python2.6/lib/python2.6/ctypes/_endian.pyc matches /opt/python2.6/lib/python2.6/ctypes/_endian.py
import ctypes._endian # precompiled from /opt/python2.6/lib/python2.6/ctypes/_endian.pyc
dlopen("/opt/python2.6/lib/python2.6/site-packages/PIL/_imaging.so", 2);
import PIL._imaging # dynamically loaded from /opt/python2.6/lib/python2.6/site-packages/PIL/_imaging.so
# /opt/python2.6/lib/python2.6/site-packages/PIL/ImageMode.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/ImageMode.py
import PIL.ImageMode # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/ImageMode.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/ImagePalette.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/ImagePalette.py
import PIL.ImagePalette # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/ImagePalette.pyc
dlopen("/opt/python2.6/lib/python2.6/lib-dynload/array.so", 2);
import array # dynamically loaded from /opt/python2.6/lib/python2.6/lib-dynload/array.so
# /opt/python2.6/lib/python2.6/string.pyc matches /opt/python2.6/lib/python2.6/string.py
import string # precompiled from /opt/python2.6/lib/python2.6/string.pyc
# /opt/python2.6/lib/python2.6/re.pyc matches /opt/python2.6/lib/python2.6/re.py
import re # precompiled from /opt/python2.6/lib/python2.6/re.pyc
# /opt/python2.6/lib/python2.6/sre_compile.pyc matches /opt/python2.6/lib/python2.6/sre_compile.py
import sre_compile # precompiled from /opt/python2.6/lib/python2.6/sre_compile.pyc
import _sre # builtin
# /opt/python2.6/lib/python2.6/sre_parse.pyc matches /opt/python2.6/lib/python2.6/sre_parse.py
import sre_parse # precompiled from /opt/python2.6/lib/python2.6/sre_parse.pyc
# /opt/python2.6/lib/python2.6/sre_constants.pyc matches /opt/python2.6/lib/python2.6/sre_constants.py
import sre_constants # precompiled from /opt/python2.6/lib/python2.6/sre_constants.pyc
dlopen("/opt/python2.6/lib/python2.6/lib-dynload/strop.so", 2);
import strop # dynamically loaded from /opt/python2.6/lib/python2.6/lib-dynload/strop.so
dlopen("/opt/python2.6/lib/python2.6/lib-dynload/operator.so", 2);
import operator # dynamically loaded from /opt/python2.6/lib/python2.6/lib-dynload/operator.so
>>> trial_image=Image.open("/tmp/jordanthecoder.jpg")
# /opt/python2.6/lib/python2.6/site-packages/PIL/BmpImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/BmpImagePlugin.py
import PIL.BmpImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/BmpImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/ImageFile.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/ImageFile.py
import PIL.ImageFile # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/ImageFile.pyc
# /opt/python2.6/lib/python2.6/traceback.pyc matches /opt/python2.6/lib/python2.6/traceback.py
import traceback # precompiled from /opt/python2.6/lib/python2.6/traceback.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/GifImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/GifImagePlugin.py
import PIL.GifImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/GifImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/JpegImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/JpegImagePlugin.py
import PIL.JpegImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/JpegImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/PpmImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/PpmImagePlugin.py
import PIL.PpmImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/PpmImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/PngImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/PngImagePlugin.py
import PIL.PngImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/PngImagePlugin.pyc
>>> trial_image.verify()
>>> fake_image = Image.open("/tmp/fakeimage.jpg") #text file ending in .jpg
# /opt/python2.6/lib/python2.6/site-packages/PIL/CurImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/CurImagePlugin.py
import PIL.CurImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/CurImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/ArgImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/ArgImagePlugin.py
import PIL.ArgImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/ArgImagePlugin.pyc
import marshal # builtin
# /opt/python2.6/lib/python2.6/site-packages/PIL/Hdf5StubImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/Hdf5StubImagePlugin.py
import PIL.Hdf5StubImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/Hdf5StubImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/MspImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/MspImagePlugin.py
import PIL.MspImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/MspImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/MicImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/MicImagePlugin.py
import PIL.MicImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/MicImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/TiffImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/TiffImagePlugin.py
import PIL.TiffImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/TiffImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/OleFileIO.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/OleFileIO.py
import PIL.OleFileIO # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/OleFileIO.pyc
# /opt/python2.6/lib/python2.6/StringIO.pyc matches /opt/python2.6/lib/python2.6/StringIO.py
import StringIO # precompiled from /opt/python2.6/lib/python2.6/StringIO.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/FitsStubImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/FitsStubImagePlugin.py
import PIL.FitsStubImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/FitsStubImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/MpegImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/MpegImagePlugin.py
import PIL.MpegImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/MpegImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/PixarImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/PixarImagePlugin.py
import PIL.PixarImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/PixarImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/DcxImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/DcxImagePlugin.py
import PIL.DcxImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/DcxImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/PcxImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/PcxImagePlugin.py
import PIL.PcxImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/PcxImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/WmfImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/WmfImagePlugin.py
import PIL.WmfImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/WmfImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/XVThumbImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/XVThumbImagePlugin.py
import PIL.XVThumbImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/XVThumbImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/XbmImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/XbmImagePlugin.py
import PIL.XbmImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/XbmImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/ImtImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/ImtImagePlugin.py
import PIL.ImtImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/ImtImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/IptcImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/IptcImagePlugin.py
import PIL.IptcImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/IptcImagePlugin.pyc
# /opt/python2.6/lib/python2.6/tempfile.pyc matches /opt/python2.6/lib/python2.6/tempfile.py
import tempfile # precompiled from /opt/python2.6/lib/python2.6/tempfile.pyc
# /opt/python2.6/lib/python2.6/random.pyc matches /opt/python2.6/lib/python2.6/random.py
import random # precompiled from /opt/python2.6/lib/python2.6/random.pyc
# /opt/python2.6/lib/python2.6/__future__.pyc matches /opt/python2.6/lib/python2.6/__future__.py
import __future__ # precompiled from /opt/python2.6/lib/python2.6/__future__.pyc
dlopen("/opt/python2.6/lib/python2.6/lib-dynload/math.so", 2);
import math # dynamically loaded from /opt/python2.6/lib/python2.6/lib-dynload/math.so
dlopen("/opt/python2.6/lib/python2.6/lib-dynload/binascii.so", 2);
import binascii # dynamically loaded from /opt/python2.6/lib/python2.6/lib-dynload/binascii.so
dlopen("/opt/python2.6/lib/python2.6/lib-dynload/_random.so", 2);
import _random # dynamically loaded from /opt/python2.6/lib/python2.6/lib-dynload/_random.so
dlopen("/opt/python2.6/lib/python2.6/lib-dynload/cStringIO.so", 2);
import cStringIO # dynamically loaded from /opt/python2.6/lib/python2.6/lib-dynload/cStringIO.so
dlopen("/opt/python2.6/lib/python2.6/lib-dynload/fcntl.so", 2);
import fcntl # dynamically loaded from /opt/python2.6/lib/python2.6/lib-dynload/fcntl.so
import thread # builtin
# /opt/python2.6/lib/python2.6/site-packages/PIL/GribStubImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/GribStubImagePlugin.py
import PIL.GribStubImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/GribStubImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/TgaImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/TgaImagePlugin.py
import PIL.TgaImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/TgaImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/BufrStubImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/BufrStubImagePlugin.py
import PIL.BufrStubImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/BufrStubImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/FpxImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/FpxImagePlugin.py
import PIL.FpxImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/FpxImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/SgiImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/SgiImagePlugin.py
import PIL.SgiImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/SgiImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/FliImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/FliImagePlugin.py
import PIL.FliImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/FliImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/PcdImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/PcdImagePlugin.py
import PIL.PcdImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/PcdImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/PalmImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/PalmImagePlugin.py
import PIL.PalmImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/PalmImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/XpmImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/XpmImagePlugin.py
import PIL.XpmImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/XpmImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/ImImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/ImImagePlugin.py
import PIL.ImImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/ImImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/SunImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/SunImagePlugin.py
import PIL.SunImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/SunImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/IcnsImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/IcnsImagePlugin.py
import PIL.IcnsImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/IcnsImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/McIdasImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/McIdasImagePlugin.py
import PIL.McIdasImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/McIdasImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/PdfImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/PdfImagePlugin.py
import PIL.PdfImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/PdfImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/GbrImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/GbrImagePlugin.py
import PIL.GbrImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/GbrImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/EpsImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/EpsImagePlugin.py
import PIL.EpsImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/EpsImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/IcoImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/IcoImagePlugin.py
import PIL.IcoImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/IcoImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/SpiderImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/SpiderImagePlugin.py
import PIL.SpiderImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/SpiderImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/PsdImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/PsdImagePlugin.py
import PIL.PsdImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/PsdImagePlugin.pyc
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/python2.6/lib/python2.6/site-packages/PIL/Image.py", line 1916, in open
    raise IOError("cannot identify image file")
IOError: cannot identify image file

更新

这是$ python manage.py shell(跳过初始import语句)的输出:

Here is the output for $ python manage.py shell (skipping initial import statements):

Python 2.6.4 (r264:75706, Jan 15 2010, 14:42:33) 
[GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from PIL import Image
import PIL # directory /opt/python2.6/lib/python2.6/site-packages/PIL
# /opt/python2.6/lib/python2.6/site-packages/PIL/__init__.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/__init__.py
import PIL # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/__init__.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/Image.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/Image.py
import PIL.Image # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/Image.pyc
# /opt/python2.6/lib/python2.6/lib-tk/FixTk.pyc matches /opt/python2.6/lib/python2.6/lib-tk/FixTk.py
import FixTk # precompiled from /opt/python2.6/lib/python2.6/lib-tk/FixTk.pyc
import ctypes # directory /opt/python2.6/lib/python2.6/ctypes
# /opt/python2.6/lib/python2.6/ctypes/__init__.pyc matches /opt/python2.6/lib/python2.6/ctypes/__init__.py
import ctypes # precompiled from /opt/python2.6/lib/python2.6/ctypes/__init__.pyc
dlopen("/opt/python2.6/lib/python2.6/lib-dynload/_ctypes.so", 2);
import _ctypes # dynamically loaded from /opt/python2.6/lib/python2.6/lib-dynload/_ctypes.so
# /opt/python2.6/lib/python2.6/ctypes/_endian.pyc matches /opt/python2.6/lib/python2.6/ctypes/_endian.py
import ctypes._endian # precompiled from /opt/python2.6/lib/python2.6/ctypes/_endian.pyc
dlopen("/opt/python2.6/lib/python2.6/site-packages/PIL/_imaging.so", 2);
import PIL._imaging # dynamically loaded from /opt/python2.6/lib/python2.6/site-packages/PIL/_imaging.so
# /opt/python2.6/lib/python2.6/site-packages/PIL/ImageMode.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/ImageMode.py
import PIL.ImageMode # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/ImageMode.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/ImagePalette.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/ImagePalette.py
import PIL.ImagePalette # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/ImagePalette.pyc
>>> trial_image=Image.open("/tmp/jordanthecoder.jpg")
# /opt/python2.6/lib/python2.6/site-packages/PIL/BmpImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/BmpImagePlugin.py
import PIL.BmpImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/BmpImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/ImageFile.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/ImageFile.py
import PIL.ImageFile # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/ImageFile.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/GifImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/GifImagePlugin.py
import PIL.GifImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/GifImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/JpegImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/JpegImagePlugin.py
import PIL.JpegImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/JpegImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/PpmImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/PpmImagePlugin.py
import PIL.PpmImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/PpmImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/PngImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/PngImagePlugin.py
import PIL.PngImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/PngImagePlugin.pyc
>>> trial_image.verify()
>>> 

更新#2:

好的,所以我决定完全绕过ImageField,看看PIL是怎么做的。这是有问题的代码(在我的views.py文件中):

Okay, so I decided to bypass ImageField altogether and just see what PIL does on its own. This is the code in question (in my views.py file):

def test_image(request):
    i = Image.open("/tmp/jordanthecoder.jpg")
    t = i.verify()
    return HttpResponse("Image is "+repr(i.info))

这是网页输出:

Image is {'jfif_version': (1, 1), 'jfif': 257, 'jfif_unit': 1, 'jfif_density': (72, 72), 'dpi': (72, 72)}

更新#3

所以,这些是模块和两个不同系统的路径。我不知道为什么他们是如此不同,我可以做什么来改变网页的行为。

So, these are the modules and paths for the two different systems. I'm not exactly sure why they're so different and what I can do to change the behavior of the web version.

他们实际上正在使用不同的JSON模块,漂亮这确实没有什么不同。除此之外,这里是不同的模块。假设这些模块都位于/opt/python2.6 /...

They actually were using different JSON modules, pretty sure that that makes no difference. Other than that, here are the different modules. Assume these modules are all somewhere in /opt/python2.6/...

只有在网络版本中:

django.contrib.sessions.*, django.core.email, django.core.handlers.*, django.core.mail, django.core.mimetypes, django.core.os, django.core.random, django.core.smtplib, django.core.socket, django.core.time, django.middleware.*, email.*, encodings.ascii, hmac, mimetypes, mod_wsgi, smtplib, uu

只有在shell版本中:

Only in the shell version:

code, codeop, django.core.management.*, readline, rlcompleter, settings, user

谢谢

**更新#4 **

** UPDATE #4 **

看起来问题是apache使用不正确的libjpeg.so,而python正在使用正确的。我创建了一个更多的广义版本的问题,特定于Django

Looks like the problem is that apache is using the incorrect libjpeg.so, whereas python is using the right one. I've created a more generalized version of the question that isn't specific to Django.

推荐答案

查看可能的答案:

是否可以控制apache使用的库?

此处的引用如果被授予,仍然可以获得赏金。 : - )

Referencing here so can still get bounty if awarded. :-)

这篇关于在Django中获取无效的图像错误,但PIL已安装并通过所有测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆