简体   繁体   English

python运行时中Appengine开发服务器上的模块初始化错误

[英]Module initialization error on appengine dev server in python runtime

I am creating a new python appengine application with 2 modules (2 yamls). 我正在创建一个具有2个模块(2个Yamls)的新python appengine应用程序。 The default yaml is app.yaml with sits in my project root directory. 默认的yaml是app.yaml,位于我的项目根目录中。 The second yaml file module1.yaml which sits in the module1 directory. 第二个yaml文件module1.yaml位于module1目录中。 I have the following configuration in module1.yaml 我在module1.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

In the same module1 directory, I have the file module1.app which has the following code 在相同的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)

In the same module1 directory I have routes.py which contains by routing configuration. 在相同的module1目录中,我具有按路由配置包含的route.py。

When I start the dev server using the following command 当我使用以下命令启动开发服务器时

python dev_appserver.py app.yaml module1/module1.yaml , I receive the following output: 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 -

Can anyone explain this error to me ? 谁能向我解释这个错误? What can I do to fix this ? 我该怎么做才能解决此问题?

Directory module1 is not in sys.path -- add into it an empty __init__.py to make it a package, and change 目录module1不在sys.path -向其中添加一个空的__init__.py以使其成为一个包,然后进行更改

script: module1.app

to: 至:

script: module1.module1.module1_app

Note I've also changed the name of the WSGI app object to reflect the actual name you've chosen to use given the assignment 注意,我还更改了WSGI应用程序对象的名称,以反映给定分配后您选择使用的实际名称。

module1_app = webapp2.WSGIApplication(debug = True)

That makes far too many reps of "module1", but, hey, those are the names you've chosen to use!-) 这会使“ module1”的代表太多,但是,嘿,这些就是您选择使用的名称!-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM