在应用引擎

时间:2016-05-22 13:52:25

标签: python google-app-engine python-imaging-library nonetype

所以当我在我的控制台中运行它时,我有一段代码可以正常工作,但是当我尝试在app引擎上运行它时,它不会。

from lib.PIL import Image
import urllib, cStringIO
@endpoints.method(ImageCreateRequest, DummyResponse, http_method='POST', name='image_create')
def image_create(self, request):
    file = cStringIO.StringIO(urllib.urlopen(URL).read())
    img = Image.open(file)
    img.load()
    return DummyResponse(
        response=str(img.size)
    )

我收到以下错误

in _new

new.mode = im.mode

AttributeError: 'NoneType' object has no attribute 'mode'

编辑:确切追溯

Encountered unexpected error from ProtoRPC method implementation: AttributeError ('NoneType' object has no attribute 'mode')

Traceback (most recent call last):
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/protorpc-1.0/protorpc/wsgi/service.py", line 181, in protorpc_service_app
response = method(instance, request)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/endpoints-1.0/endpoints/api_config.py", line 1331, in invoke_remote
return remote_method(service_instance, request)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/protorpc-1.0/protorpc/remote.py", line 414, in invoke_remote_method
response = method(service_instance, request)
File "/base/data/home/apps/myproj/1.392969200987483659/post_api.py", line 100, in image_create
img = Image.open(file)
File "/base/data/home/apps/myproj/1.392969200987483659/lib/PIL/Image.py", line 1969, in open
if init():
File "/base/data/home/apps/myproj/1.392969200987483659/lib/PIL/Image.py", line 355, in init
__import__(f, globals(), locals(), [])
File "/base/data/home/apps/myproj/1.392969200987483659/lib/PIL/PalmImagePlugin.py", line 92, in <module>
Palm8BitColormapImage = build_prototype_image()
File "/base/data/home/apps/myproj/1.392969200987483659/lib/PIL/PalmImagePlugin.py", line 82, in build_prototype_image
image = Image.new("L", (1,len(_Palm8BitColormapValues),))
File "/base/data/home/apps/myproj/1.392969200987483659/lib/PIL/Image.py", line 1763, in new
return Image()._new(core.fill(mode, size, color))
File "/base/data/home/apps/myproj/1.392969200987483659/lib/PIL/Image.py", line 463, in _new
new.mode = im.mode

AttributeError:'NoneType'对象没有属性'mode'

我不太确定为什么这么简单的东西会在控制台中运行而不是在app引擎上运行。有什么想法吗?

由于

1 个答案:

答案 0 :(得分:1)

如果是生产问题,你应该试试这个 - 从您自己安装的lib文件夹中删除PIL模块。

转到app.yaml并将其粘贴到库部分下(如果没有粘贴整个部分) -

from src.models.base import Base

通过 -

调用基于appengine的模块
libraries:
  - name: PIL
    version: latest