foreman启动失败,未找到应用:'soapbar

1 投票
1 回答
1189 浏览
提问于 2025-04-17 23:08

我正在按照这个快速入门指南操作:https://devcenter.heroku.com/articles/getting-started-with-python

但是在执行 foreman start 的时候卡住了。我的文件夹结构是这样的。我只是运行一个基本的网页应用,没有使用任何框架。

soapbar/
    Procfile.txt
    soapbar/
        soapbar.py
        __init__.py
    venv/
        Include/
        Lib/
        Scripts/ 

这是我 Procfile 文件里的内容:

web: gunicorn soapbar.soapbar:app

这是错误追踪信息:

09:28:54 web.1  | started with pid 34567
09:28:54 web.1  | 2014-03-20 09:28:54 [34567] [INFO] Starting gunicorn 18.0
09:28:54 web.1  | 2014-03-20 09:28:54 [34567] [INFO] Listening at: http://0.0.0.0:5000 (34567)
09:28:54 web.1  | 2014-03-20 09:28:54 [34567] [INFO] Using worker: sync
09:28:54 web.1  | 2014-03-20 09:28:54 [34570] [INFO] Booting worker with pid: 34570
09:28:54 web.1  | Failed to find application: 'soapbar.soapbar'
09:28:54 web.1  | 2014-03-20 09:28:54 [34570] [INFO] Worker exiting (pid: 34570)
09:28:54 web.1  | 2014-03-20 09:28:54 [34567] [INFO] Shutting down: Master
09:28:54 web.1  | 2014-03-20 09:28:54 [34567] [INFO] Reason: App failed to load.
09:28:54 web.1  | exited with code 4
09:28:54 system | sending SIGTERM to all processes
SIGTERM received

请帮帮我。

这是 soapbar.py 文件:

import logging
import os

from spyne.application import Application
from spyne.decorator import srpc
from spyne.interface.wsdl import Wsdl11
from spyne.protocol.soap import Soap11
from spyne.service import ServiceBase
from spyne.model.complex import Iterable
from spyne.model.primitive import Integer
from spyne.model.primitive import String
from spyne.server.wsgi import WsgiApplication

class MessageService(ServiceBase):
    @srpc(String, Integer, _returns=Iterable(String))
    def send_message(msg):
        yield 'Your message: %s' % msg

if __name__=='__main__':
    try:
        from wsgiref.simple_server import make_server
    except ImportError:
        print "Error: server requires Python >= 2.5"

    logging.basicConfig(level=logging.INFO)
    logging.getLogger('spyne.protocol.xml').setLevel(logging.DEBUG)

    application = Application([MessageService], 'org.temporary.soap',
            interface=Wsdl11(), in_protocol=Soap11(), out_protocol=Soap11())

    port = int(os.environ.get('PORT', 5000))

    server = make_server('0.0.0.0', port, WsgiApplication(application))

    print "listening to http://0.0.0.0:%s" % port
    print "wsdl is at: http://0.0.0.0:%s/?wsdl" % port

    server.serve_forever()

1 个回答

0

这可能不是你所有的问题,但看看Heroku在那个教程中用的Flask示例,他们在Python文件中实际上定义了一个'app'变量(也就是wsgi服务器),而这个变量并不在main下面。这就是为什么他们的foreman文件里有 :app。你的文件里也有 :app,但你并没有定义一个app。

import os
from flask import Flask

app = Flask(__name__)

@app.route('/')
def hello():
    return 'Hello World!'

撰写回答