Heroku上的枕头不起作用

时间:2013-05-23 06:46:29

标签: django heroku python-2.7 pillow

我正在使用Django1.4.3和Pillow2.0.0开发一个应用程序。

我有一张上传图片文件的表单 调整大小并裁剪发布的图像文件后,
我想保存图像文件,但发生错误。

在django的本地测试服务器中,错误不会发生并且运行良好,
但是在Heroku中,会发生错误。

你能告诉我一些建议吗? 接收发布图像的代码如下。 另外,我使用S3boto和django-storage。

def edit_photo(request):
    if request.user.is_authenticated():
        if request.method == 'POST':
            # save posted image as UserProfile.image temporarily
            posted_photo = request.FILES['posted_photo']
            file_content = ContentFile(posted_photo.read())
            profile = request.user.get_profile()
            temp_filename = "new_file_"+str(profile.id)+"_"+posted_photo.name
            profile.image.save(temp_filename, file_content)

            # read posted file
            data = profile.image.read()
            im = Image.open(StringIO.StringIO(data))

            # crop posted image
            cropping_box = (10, 10, 300, 300)
            photo = photo.crop(cropping_box)
            photo_comp = photo.resize((230, 230), Image.ANTIALIAS)

            # save the image
            thum = StringIO.StringIO()
            photo_comp.save(thum, "png")
            profile.image.save("saved_image_"+str(profile.id)+".png",ContentFile(thum.getvalue()))

            # delete temporary image
            default_storage.delete("faces/"+temp_filename)

            return redirect('../')

错误信息是这样的。

    TypeError at /manage/edit_photo
    function takes at most 4 arguments (6 given)
    Request Method: POST
    Request URL:    http://hogehoge.herokuapp.com/manage/edit_photo
    Django Version: 1.4.3
    Exception Type: TypeError
    Exception Value:    
    function takes at most 4 arguments (6 given)
    Exception Location: /app/.heroku/python/lib/python2.7/site-packages/PIL/Image.py in _getencoder, line 395
    Python Executable:  /app/.heroku/python/bin/python
    Python Version: 2.7.4
    Python Path:    
    ['/app',
     '/app/.heroku/python/lib/python2.7/site-packages/pip-1.3.1-py2.7.egg',
     '/app/.heroku/python/lib/python2.7/site-packages/newrelic-1.11.0.55/newrelic/bootstrap',
     '/app',
     '/app/.heroku/python/lib/python27.zip',
     '/app/.heroku/python/lib/python2.7',
     '/app/.heroku/python/lib/python2.7/plat-linux2',
     '/app/.heroku/python/lib/python2.7/lib-tk',
     '/app/.heroku/python/lib/python2.7/lib-old',
     '/app/.heroku/python/lib/python2.7/lib-dynload',
     '/app/.heroku/python/lib/python2.7/site-packages',
     '/app/.heroku/python/lib/python2.7/site-packages/PIL',
     '/app/.heroku/python/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg-info']

    /app/.heroku/python/lib/python2.7/site-packages/django/core/handlers/base.py in get_response
                            response = callback(request, *callback_args, **callback_kwargs) ...
    ▶ Local vars
    /app/movie_manager/views.py in edit_photo
                photo_comp.save(thum, "png") ...
    ▶ Local vars
    /app/.heroku/python/lib/python2.7/site-packages/PIL/Image.py in save
                save_handler(self, fp, filename) ...
    ▶ Local vars
    /app/.heroku/python/lib/python2.7/site-packages/PIL/PngImagePlugin.py in _save
        ImageFile._save(im, _idat(fp, chunk), [("zip", (0,0)+im.size, 0, rawmode)]) ...
    ▶ Local vars
    /app/.heroku/python/lib/python2.7/site-packages/PIL/ImageFile.py in _save
                e = Image._getencoder(im.mode, e, a, im.encoderconfig) ...
    ▶ Local vars
    /app/.heroku/python/lib/python2.7/site-packages/PIL/Image.py in _getencoder
            return encoder(mode, *args + extra) ...
    ▶ Local vars

1 个答案:

答案 0 :(得分:1)

对于发现此问题的其他人......

当同时安装PIL和Pillow时可能会发生此TypeError(可能是由于隐藏的包要求而无意中)。您需要卸载两个 PIL和Pillow,然后重新安装所需的那个。