python运行时appengine dev服务器上的模块初始化错误



我正在创建一个新的python appengine应用程序,其中包含2个模块(2个yaml)。默认的yaml是app.yaml,位于我的项目根目录中。第二个yaml文件module1.yaml位于module1目录中。我在模块1.yaml 中有以下配置

application: appID
module: module1
version: default
runtime: python27
api_version: 1
threadsafe: true
instance_class: F1
automatic_scaling:
  min_idle_instances: automatic
  max_idle_instances: automatic
  min_pending_latency: 500ms
  max_pending_latency: 1000ms
  max_concurrent_requests: 50
handlers:
- url: .*
  script: module1.app
libraries:
- name: webapp2
  version: latest
- name: MySQLdb
  version: latest
- name: ssl
  version: latest
inbound_services:
- warmup
- xmpp_message
- xmpp_presence
- xmpp_subscribe
- xmpp_error

在同一个module1目录中,我有一个文件module1.app,它有以下代码

#!/usr/bin/env python
import sys
import webapp2
# Module Imports
import routes
# Define app
module1_app = webapp2.WSGIApplication(debug = True)
# Add to path
if 'libs' not in sys.path:
    sys.path[0:0] = ['libs']
# Add defined routes
routes.add_routes(module1_app)

在同一个module1目录中,我有routes.py,其中包含路由配置。

当我使用以下命令启动开发服务器时

python dev_appserver.py app.yaml module1/module1.yaml,我收到以下输出:

INFO     2015-03-18 15:56:05,149 api_server.py:172] Starting API server at: http://localhost:38640
INFO     2015-03-18 15:56:05,159 dispatcher.py:185] Starting module "default" running at: http://localhost:8080
INFO     2015-03-18 15:56:05,164 dispatcher.py:185] Starting module "module1" running at: http://localhost:8081
INFO     2015-03-18 15:56:05,167 admin_server.py:118] Starting admin server at: http://localhost:8000
ERROR    2015-03-18 15:56:06,493 wsgi.py:263] 
Traceback (most recent call last):
  File "/home/user1/servers/gae/google/appengine/runtime/wsgi.py", line 240, in Handle
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
  File "/home/user1/servers/gae/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
    handler, path, err = LoadObject(self._handler)
  File "/home/user1/servers/gae/google/appengine/runtime/wsgi.py", line 85, in LoadObject
    obj = __import__(path[0])
ImportError: No module named module1
INFO     2015-03-18 15:56:06,510 module.py:709] comm: "GET /_ah/warmup HTTP/1.1" 500 -

有人能向我解释这个错误吗?我能做些什么来解决这个问题?

目录module1不在sys.path中--添加一个空的__init__.py使其成为一个包,并更改

script: module1.app

至:

script: module1.module1.module1_app

注意,我还更改了WSGI应用程序对象的名称,以反映您在给定分配时选择使用的实际名称

module1_app = webapp2.WSGIApplication(debug = True)

这使得"module1"的重复次数太多了,但是,嘿,那些是你选择使用的名称!-)

相关内容

  • 没有找到相关文章

最新更新