1

再会!

https://developers.google.com/appengine/docs/python/gettingstarted/helloworld
这是我试图运行的hello world。

我可以看到

Hello, world!
Status: 500

信息。但是在我刷新后它会变成“HTTP错误500”。
并且...似乎在我重新保存 app.yaml 或 helloworld.py 后,appengine 只向我显示了一次良好的结果

这是良好结果的跟踪

Traceback (most recent call last):
  File "C:\Program Files\Google\google_appengine\google\appengine\runtime\wsgi.py", line 187, in Handle
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
  File "C:\Program Files\Google\google_appengine\google\appengine\runtime\wsgi.py", line 239, in _LoadHandler
    raise ImportError('%s has no attribute %s' % (handler, name))
ImportError: <module 'helloworld' from 'D:\work\[GAE] tests\helloworld\helloworld.pyc'> has no attribute app
INFO     2012-06-23 01:47:28,522 dev_appserver.py:2891] "GET /hello HTTP/1.1" 200 -
ERROR    2012-06-23 01:47:30,040 wsgi.py:189] 

这是错误 500 的跟踪

Traceback (most recent call last):
  File "C:\Program Files\Google\google_appengine\google\appengine\runtime\wsgi.py", line 187, in Handle
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
  File "C:\Program Files\Google\google_appengine\google\appengine\runtime\wsgi.py", line 239, in _LoadHandler
    raise ImportError('%s has no attribute %s' % (handler, name))
ImportError: <module 'helloworld' from 'D:\work\[GAE] tests\helloworld\helloworld.pyc'> has no attribute app
INFO     2012-06-23 01:47:30,127 dev_appserver.py:2891] "GET /hello HTTP/1.1" 500 -


这是我的 helloworld.py

print 'Content-Type: text/plain'
print ''
print 'Hello, world!'

我的主要.py。(应用程序代替应用程序)

import webapp2

class hello(webapp2.RequestHandler):
    def get(self):
        self.response.out.write('normal hello')

app = webapp2.WSGIApplication([
    ('/', hello),
], debug = True)

和 app.yaml

application: helloworld
version: 1
runtime: python27
api_version: 1
threadsafe: true

handlers:
- url: /favicon\.ico
  static_files: favicon.ico
  upload: favicon\.ico

- url: /hello
  script: helloworld.app

- url: /.*
  script: main.app

libraries:
- name: webapp2
  version: "2.5.1"


任何线索是什么原因造成的?

问候,

4

1 回答 1

3

您没有helloworld.app在 helloworld.py 模块中创建对象。

看线

app = webapp2.WSGIApplications([...

在你的 main.py 文件中?script: main.app这将创建app.yaml 中的处理程序引用的 main.app 对象。

您在helloworld.app上面几行引用了一个对象;该对象不存在。App Engine 中的 Python 2.7 不支持在 2.5“Hello World”演示中使用的简单模块模型——没有 WSGI 处理程序,只有一个简单的脚本。

正如 presveva 所说,使用 2.7 入门指南可以减少混淆。

于 2012-06-23T03:12:49.857 回答