0

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
4

1 に答える 1

1

この問題を見つけた他の人のために...

これTypeErrorは、PIL と Pillow が同時にインストールされた場合に発生する可能性があります (おそらく、非表示のパッケージ要件が原因で誤って発生した可能性があります)。PIL と Pillow の両方をアンインストールし、必要なものだけを再インストールする必要があります。

于 2013-06-21T11:30:41.900 に答える