【问题标题】:Google App Engine Guestbook application gives errorGoogle App Engine 留言簿应用程序出现错误
【发布时间】:2014-01-17 21:04:20
【问题描述】:

我上传了 Google App Engine 应用程序,网址为 developers.google.com/appengine/docs/python/memcache/usingmemcache#Memcache

当我在 Google App Engine Launcher 上运行应用程序时,它会运行,但网站显示: (第一个错误是我们没有 Python “PIL” 模块,但我没有使用图像。您能否建议导致错误的原因?

*** Running dev_appserver with the following flags:
    --skip_sdk_update_check=yes --port=13080 --admin_port=8005
Python command: /usr/bin/python2.7
INFO     2014-01-17 20:43:22,217 devappserver2.py:660] Skipping SDK update check.
WARNING  2014-01-17 20:43:22,222 api_server.py:331] Could not initialize images API; you are likely missing the Python "PIL" module.
INFO     2014-01-17 20:43:22,226 api_server.py:138] Starting API server at: localhost:55385
INFO     2014-01-17 20:43:22,230 dispatcher.py:171] Starting module "default" running at: localhost:13080
INFO     2014-01-17 20:43:22,238 admin_server.py:117] Starting admin server at: localhost:8005
ERROR    2014-01-17 20:43:24,601 wsgi.py:262] 
Traceback (most recent call last):
  File "/Users/Desktop/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 239, in Handle
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
  File "/Users/Desktop/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 301, in _LoadHandler
    raise err
ImportError: <module 'guestbookw2' from '/Users/guestbookw2/guestbookw2.pyc'> has no attribute application
INFO     2014-01-17 20:43:24,607 module.py:617] default: "GET / HTTP/1.1" 500 -
ERROR    2014-01-17 20:43:24,727 wsgi.py:262] 
Traceback (most recent call last):
  File "/Users/Desktop/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 239, in Handle
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
  File "/Users/Desktop/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 301, in _LoadHandler
    raise err
ImportError: <module 'guestbookw12' from '/Users/guestbookw2/guestbookw2.pyc'> has no attribute application
INFO     2014-01-17 20:43:24,732 module.py:617] default: "GET /favicon.ico HTTP/1.1" 500 -

【问题讨论】:

  • 下面的答案至少解决了上述问题中列出的错误之一(“GET /favicon.ico ...”),因此一开始就拒绝投票并不是很有礼貌。

标签: google-app-engine


【解决方案1】:

确保您上传应用程序的路径中有以下文件:

  1. index.yaml(自动生成;此时您无需在此处添加或更改任何内容)。

  2. favicon.ico(格式正确;如果我没记错的话应该是 16x16 或 32x32 像素)。

  3. ma​​in.py(映射您网站中的所有路径;示例如下):

    from webapp2 import WSGIApplication
    from Server import MainRequestHandler
    from Server import SomeRequestHandler
    from Server import OtherRequestHandler
    
    app = WSGIApplication([
        ('/'              ,MainRequestHandler),
        ('/abc'           ,SomeRequestHandler),
        ('/def'           ,SomeRequestHandler),
        ('/xyz'           ,OtherRequestHandler),
    ])
    
  4. app.yaml(内容如下;在需要设置值的地方使用&lt;...&gt;):

    application: <the app-id you chose when use signed in for GAE>
    version: 1
    runtime: python27
    api_version: 1
    threadsafe: yes
    
    handlers:
    - url: /favicon\.ico
      static_files: favicon.ico
      upload: favicon\.ico
    
    - url: .*
      script: main.app
    
    libraries:
    - name: webapp2
      version: "2.5.1" // you might need to change this as well
    

注意

如果您希望避免处理“favicon.ico”请求,则必须删除文件“app.yaml”中的引用。

补充

您将需要实现在“main.py”中导入的所有请求处理程序。

在上面的示例中,“main.py”希望在名为“Server”的 Python 模块中找到它们。

每个请求处理程序都必须继承 class RequestHandler,从 webapp2 导入。

补充 #2

为了解决“PIL”问题(如果内存正常,也会出现类似问题),只需安装它。

在 Windows 命令行中,输入:pip install pil。

【讨论】:

  • 我更新了 main.py 文件。我写的不是“app =”,而是“application =”......现在它可以工作了。
  • 首先,如果在 app.yaml 文件中有'script: main.app'(如我上面的回答),那么这个变量的名称应该是app。因此,您的 app.yaml 文件中可能有“脚本:main.application”。其次,你为什么不赞成这个答案???
  • 是的,在我的 app.yaml 文件中它是 main.application 。谢谢。我没有投反对票。我什至没有在登录时看到任何投票标志。
猜你喜欢
  • 2011-03-07
  • 2011-07-11
  • 2017-10-02
  • 1970-01-01
  • 2019-07-12
  • 2020-08-31
  • 1970-01-01
  • 2014-03-11
  • 2016-07-30
相关资源
最近更新 更多