将GAE Webapp2与多个文件中的类一起使用

时间:2012-10-06 16:55:56

标签: python google-app-engine webapp2

我遇到了Webapp2的问题。当我在app.yaml中为指向不同python文件的URL放置处理程序时,我收到以下错误:

ERROR    2012-10-06 16:44:57,759 wsgi.py:203] 
Traceback (most recent call last):
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 195, in Handle
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 250, in _LoadHandler
    __import__(cumulative_path)
ImportError: No module named application

我的app.yaml:

application: [[app's name]]
version: 1
runtime: python27
api_version: 1
threadsafe: yes

inbound_services:
- mail

handlers:

- url: /send
  script: email.application

- url: /_ah/mail/update@sitdown-standup.appspotmail.com.*
  script: email.application

- url: /.*
  script: SDSUmodels.application

libraries:
- name: webapp2
  version: "2.5.1"

SDSUmodels.py以:

结尾
application = webapp2.WSGIApplication([('/info', MakeBasicInfo)], 
                                   debug=True)`

和email.py以:

结尾
application = webapp2.WSGIApplication([('/request', Request_update),
                                   ('/send', Send_report),
                                   (Receive_email.mapping())], 
                                   debug=True)`

当我删除这些行

- url: /send
  script: email.application
从app.yaml

,错误停止,但这使我无法将URL指向特定文件。

我可以在this question中看到一些处理此问题的替代方法,但我想知道为什么这种方法不起作用。我之前已经使用旧的webapp版本在不同的项目中完成了这项工作 - 它的工作原理 - 详情如下。

的app.yaml:

application: [[other app's name]]
version: 1
runtime: python
api_version: 1

handlers:
- url: /stylesheets
  static_dir: stylesheets

- url: /twitter
  script: twitter.py

- url: /_ah/mail/kindle@shelvdtracker.appspotmail.com.*
  script: kindle.py

- url: /.*
  script: web.py

inbound_services:
- mail

twitter.py以:

结尾
application = webapp.WSGIApplication(
                                     [('/twitter', Process_new_DM)],
                                     debug=True)

def main():
    run_wsgi_app(application)

if __name__ == "__main__":
    main()

1 个答案:

答案 0 :(得分:3)

还有一个名为email的标准库;它是在找到本地模块之前加载的。

将模块重命名为其他内容并且它可以正常工作。