【问题标题】:foreman start failed to find application: 'soapbar'工头开始找不到应用程序:'soapbar'
【发布时间】:2014-04-27 09:23:43
【问题描述】:

我在这里关注 heroku 快速入门指南:https://devcenter.heroku.com/articles/getting-started-with-python

我被困在工头开始部分。这是我的目录的样子。我只是在运行一个基本的网络应用程序。没有框架或任何东西。

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()

【问题讨论】:

  • 您的 PYTHONPATH 设置是否正确,包括模块的位置?
  • PYTHONPATH?我使用的是 venv 环境,所以没关系吧?
  • 不确定,但检查一下不会有什么坏处:stackoverflow.com/questions/4757178/…
  • 由 PYTHONPATH 修改,但它不起作用:/。似乎它以某种方式知道它在哪里,因为当我删除初始化文件时,我得到了找不到模块。所以 gunicorn 知道它在那里,但它找不到应用程序?
  • 如果您将 Procfile 更改为 web:gunicorn soapbar.soapbar2:app,您会得到不同的错误吗? soapbar.py 有多大?你能贴吗?问题可能出在里面。

标签: python heroku flask


【解决方案1】:

这可能不是你的全部问题,但看看 heroku 在该教程中使用的烧瓶示例,它们实际上在 python 文件中定义了一个“app”变量(wsgi server)(不在 ma​​in强>)。这就是为什么他们的工头文件有:app。你的也有 :app,但你没有定义应用程序。

import os
from flask import Flask

app = Flask(__name__)

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-01-02
    • 1970-01-01
    • 2021-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多