0

在此处输入图像描述

我正在尝试将项目https://github.com/kc1/flask-huey-example部署到 heroku 以允许使用任务队列和烧瓶。项目布局如上。您还可以查看我更新的 github 存储库。该项目在 Windows 上本地运行没有问题(本地不使用 gunicorn)。

我的档案:

web: gunicorn run_app:app
worker: python /app/.heroku/python/bin/huey_consumer run_huey.huey

我之前收到一个错误Failed to find application object 'app' in 'run_app'。我试图通过将 run_app.py 更改为:

from app import create_app, config

if __name__ == '__main__':

    import logging
    logging.basicConfig()
    logging.getLogger().setLevel(logging.DEBUG)

    app = create_app()
    app.run(host='localhost', port=6060, debug=True)


else:


    app = create_app()
    app.run(debug=False)

不幸的是,现在当我推到heroku时,我看到:

2018-08-16T16:37:59.253114+00:00 app[web.1]: [2018-08-16 16:37:59 +0000] [8] [ERROR] Exception in worker process
2018-08-16T16:37:59.253118+00:00 app[web.1]: Traceback (most recent call last):
2018-08-16T16:37:59.253121+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
2018-08-16T16:37:59.253123+00:00 app[web.1]:     worker.init_process()
2018-08-16T16:37:59.253124+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 129, in init_process
2018-08-16T16:37:59.253126+00:00 app[web.1]:     self.load_wsgi()
2018-08-16T16:37:59.253128+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi
2018-08-16T16:37:59.253130+00:00 app[web.1]:     self.wsgi = self.app.wsgi()
2018-08-16T16:37:59.253132+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi
2018-08-16T16:37:59.253133+00:00 app[web.1]:     self.callable = self.load()
2018-08-16T16:37:59.253135+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 52, in load
2018-08-16T16:37:59.253137+00:00 app[web.1]:     return self.load_wsgiapp()
2018-08-16T16:37:59.253139+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
2018-08-16T16:37:59.253140+00:00 app[web.1]:     return util.import_app(self.app_uri)
2018-08-16T16:37:59.253142+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/util.py", line 350, in import_app
2018-08-16T16:37:59.253144+00:00 app[web.1]:     __import__(module)
2018-08-16T16:37:59.253146+00:00 app[web.1]:   File "/app/run_app.py", line 21, in <module>
2018-08-16T16:37:59.253148+00:00 app[web.1]:     app.run(debug=False)
2018-08-16T16:37:59.253149+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 841, in run
2018-08-16T16:37:59.253151+00:00 app[web.1]:     run_simple(host, port, self, **options)
2018-08-16T16:37:59.253153+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/werkzeug/serving.py", line 814, in run_simple
2018-08-16T16:37:59.253155+00:00 app[web.1]:     inner()
2018-08-16T16:37:59.253157+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/werkzeug/serving.py", line 774, in inner
2018-08-16T16:37:59.253159+00:00 app[web.1]:     fd=fd)
2018-08-16T16:37:59.253161+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/werkzeug/serving.py", line 666, in make_server
2018-08-16T16:37:59.253162+00:00 app[web.1]:     passthrough_errors, ssl_context, fd=fd)
2018-08-16T16:37:59.253164+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/werkzeug/serving.py", line 577, in __init__
2018-08-16T16:37:59.253165+00:00 app[web.1]:     self.address_family), handler)
2018-08-16T16:37:59.253167+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/socketserver.py", line 453, in __init__
2018-08-16T16:37:59.253169+00:00 app[web.1]:     self.server_bind()
2018-08-16T16:37:59.253171+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/http/server.py", line 136, in server_bind
2018-08-16T16:37:59.253173+00:00 app[web.1]:     socketserver.TCPServer.server_bind(self)
2018-08-16T16:37:59.253181+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/socketserver.py", line 467, in server_bind
2018-08-16T16:37:59.253183+00:00 app[web.1]:     self.socket.bind(self.server_address)

我怎样才能解决这个问题?

4

2 回答 2

0

尝试在 Heroku 上运行 Flask 应用程序时遇到相同的错误,并通过删除

app.run

声明完全来自我的应用程序文件(我的名为 app.py),例如你的 run_app.py。

我的档案:

web: gunicorn -b 0.0.0.0:$PORT app:app

当我想在本地运行应用程序时,我在终端(MacOS zsh)中运行

FLASK_ENV=development flask run
于 2021-07-14T03:45:54.910 回答
0

您尝试将应用程序绑定到的端口已被另一个应用程序使用。关闭其他应用并重新部署

于 2018-08-16T16:53:15.960 回答