我正在 Elastic beanstalk 上开发一个 Django 后端系统。
当我上传 JPEG 图像文件时,出现错误decoder jpeg not available
。上传 .png 图像文件不会导致任何问题。
后端环境:
- AWS beanstalk:运行 Python 2.7 的 64 位 Amazon Linux 2014.03 v1.0.4
- 蟒蛇:2.7
- pip 包列表 Django==1.6.5 Markdown==2.4.1 MySQL-python==1.2.5 Pillow==2.5.3 boto==2.30.0 django-filter==0.7 django-storages==1.1.8 djangorestframework ==2.3.14 wsgiref==0.1.2
导致错误的源代码:
看法
normalImage = NormalImage(image=image, userProfile=request.user.profile, category = category)
normalImage.save()
模型
class NormalImage(models.Model):
userProfile = models.ForeignKey(UserProfile)
height = models.PositiveIntegerField(editable=False)
width = models.PositiveIntegerField(editable=False)
image = models.ImageField(upload_to=rename_image_file, width_field='width', height_field='height')
size = models.TextField()
price = models.PositiveIntegerField()
tags = models.ManyToManyField(Tag)
category = models.ForeignKey(Category)
created_datetime = models.DateTimeField(auto_now_add=True)
def __init__(self, *args, **kwargs):
super(NormalImage,self).__init__(*args, **kwargs)
if not self.id:
self.size = Size.determineSizeDescription(anWidth=self.width, aHeight=self.height)
self.price = Size.determinePrice(anWidth=self.width, aHeight=self.height)
def get_created_datetime_str(self):
return self.created_datetime.strftime('%Y-%m-%d %H:%M:%S')
def get_image_url(self):
return 'http://photocoapi-env-x2ezvferc7.elasticbeanstalk.com/images/' + str(self.id) + '/'
错误代码:
/me/requests/ 解码器 jpeg 处的 IOError 不可用请求方法:GET 请求 URL: http:
//photoco-env-z5cnmns3pe.elasticbeanstalk.com/me/requests/Django版本:1.6.5异常类型:IOError异常值:解码器jpeg不可用异常位置:_getdecoder中的/opt/python/run/venv/lib/python2.7/site-packages/PIL/Image.py,第413行Python可执行文件:/opt/python/run/venv/bin/python Python 版本:2.7.5 Python 路径:['/opt/python/run/venv/lib/python2.7/site-packages', '/opt/python /current/app', '/opt/python/bundle/4/app', '/opt/python/run/baselinenv/lib64/python27.zip', '/opt/python/run/baselineenv/lib64/python2. 7', '/opt/python/run/baselinenv/lib64/python2.7/plat-linux2', '/opt/python/run/baselineenv/lib64/python2.7/lib-tk', '/opt/python /run/baselinenv/lib64/python2.7/lib-old','/opt/python/run/baselinenv/lib64/python2.7/lib-dynload','/usr/lib64/python2.7','/usr/lib/python2.7', '/opt/python/run/baselinenv/lib/python2.7/site-packages']
我试图解决这个问题的方法:
- 我通过 SSH 连接到 beanstalk 服务器并使用 yum 安装在库下面
百胜:libjpeg-devel,zlib-devel,freetype-devel
然后进行符号链接
$ sudo ln -s /usr/lib64/libjpeg.so /usr/lib $ sudo ln -s /usr/lib64/zlib.so /usr/lib $ sudo ln -s /usr/lib64/freetype.so /usr/库