GAE简单请求处理程序仅运行一次

时间:2012-06-23 02:04:39

标签: python google-app-engine request handler

美好的一天!

https://developers.google.com/appengine/docs/python/gettingstarted/helloworld
这是我试图奔跑的你好世界
我可以看到

Hello, world!
Status: 500

消息。但它将转向" HTTP错误500"在我点击刷新之后。
并且......在我重新保存app.yaml或helloworld.py之后,似乎只有一个显示结果才能显示出好的结果。
这是良好结果的痕迹

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!'

我的main.py. (使用app代替应用程序)

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"


是什么导致这种情况的线索?

的问候,

1 个答案:

答案 0 :(得分:3)

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

见行

app = webapp2.WSGIApplications([...
你的main.py文件中的

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

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

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