由于 Error=H10,Flask App 在通过 Heroku 部署时导致应用程序错误

Posted

技术标签:

【中文标题】由于 Error=H10,Flask App 在通过 Heroku 部署时导致应用程序错误【英文标题】:Flask App results in Application Error when deployed through Heroku due to Error=H10 【发布时间】:2019-11-18 08:52:09 【问题描述】:

我正在尝试通过 Heroku 部署一个简单的 Flask 应用程序,但我收到 H10 错误。我在 Heroku 网站上使用 Github 手动部署。

我尝试使用命令“heroku restart”、heroku ps:scale web=1、pip freeze > requirements.txt 和 dynos 并更改我的 Procfile 以包含 -b :$PORT,更改我的烧瓶 python 中的端口文件到 app.run(debug=True, port=33507, port = int(os.environ.get('PORT', 5000)) 和 app.run(host='0.0.0.0', port=port),改变我的 repo 以匹配 https://github.com/zachwill/flask_heroku,并将 gunicorn 和 gevent 添加到 requirements.txt。

应用程序

port = int(os.environ.get('PORT', 5000))
if __name__ == '__main__':
    app.run(host='0.0.0.0', port=port)

过程文件

web: gunicorn -b :$PORT flaskapp:app

requirements.txt

gunicorn
gevent

错误

2019-07-08T19:29:05.872509+00:00 heroku[web.1]: State changed from starting to crashed
2019-07-08T19:29:05.497279+00:00 app[web.1]: [2019-07-08 19:29:05 +0000] [4] [INFO] Starting gunicorn 19.9.0
2019-07-08T19:29:05.498369+00:00 app[web.1]: [2019-07-08 19:29:05 +0000] [4] [INFO] Listening at: http://0.0.0.0:39703 (4)
2019-07-08T19:29:05.498552+00:00 app[web.1]: [2019-07-08 19:29:05 +0000] [4] [INFO] Using worker: sync
2019-07-08T19:29:05.505408+00:00 app[web.1]: [2019-07-08 19:29:05 +0000] [10] [INFO] Booting worker with pid: 10
2019-07-08T19:29:05.539492+00:00 app[web.1]: [2019-07-08 19:29:05 +0000] [10] [ERROR] Exception in worker process
2019-07-08T19:29:05.539497+00:00 app[web.1]: Traceback (most recent call last):
2019-07-08T19:29:05.539499+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
2019-07-08T19:29:05.539501+00:00 app[web.1]: worker.init_process()
2019-07-08T19:29:05.539503+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 129, in init_process
2019-07-08T19:29:05.539507+00:00 app[web.1]: self.load_wsgi()
2019-07-08T19:29:05.539510+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi
2019-07-08T19:29:05.539512+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2019-07-08T19:29:05.539514+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi
2019-07-08T19:29:05.539516+00:00 app[web.1]: self.callable = self.load()
2019-07-08T19:29:05.539518+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 52, in load
2019-07-08T19:29:05.539520+00:00 app[web.1]: return self.load_wsgiapp()
2019-07-08T19:29:05.539522+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
2019-07-08T19:29:05.539524+00:00 app[web.1]: return util.import_app(self.app_uri)
2019-07-08T19:29:05.539526+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/util.py", line 350, in import_app
2019-07-08T19:29:05.539528+00:00 app[web.1]: __import__(module)
2019-07-08T19:29:05.539530+00:00 app[web.1]: File "/app/flaskapp.py", line 4, in <module>
2019-07-08T19:29:05.539532+00:00 app[web.1]: from pml import app
2019-07-08T19:29:05.539577+00:00 app[web.1]: ModuleNotFoundError: No module named 'pml'
2019-07-08T19:29:05.539825+00:00 app[web.1]: [2019-07-08 19:29:05 +0000] [10] [INFO] Worker exiting (pid: 10)
2019-07-08T19:29:05.555645+00:00 app[web.1]: [2019-07-08 19:29:05 +0000] [11] [INFO] Booting worker with pid: 11
2019-07-08T19:29:05.574207+00:00 app[web.1]: [2019-07-08 19:29:05 +0000] [11] [ERROR] Exception in worker process
2019-07-08T19:29:05.574212+00:00 app[web.1]: Traceback (most recent call last):
2019-07-08T19:29:05.574214+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
2019-07-08T19:29:05.574216+00:00 app[web.1]: worker.init_process()
2019-07-08T19:29:05.574218+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 129, in init_process
2019-07-08T19:29:05.574220+00:00 app[web.1]: self.load_wsgi()
2019-07-08T19:29:05.574222+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi
2019-07-08T19:29:05.574224+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2019-07-08T19:29:05.574226+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi
2019-07-08T19:29:05.574228+00:00 app[web.1]: self.callable = self.load()
2019-07-08T19:29:05.574230+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 52, in load
2019-07-08T19:29:05.574232+00:00 app[web.1]: return self.load_wsgiapp()
2019-07-08T19:29:05.574234+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
2019-07-08T19:29:05.574236+00:00 app[web.1]: return util.import_app(self.app_uri)
2019-07-08T19:29:05.574238+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/util.py", line 350, in import_app
2019-07-08T19:29:05.574240+00:00 app[web.1]: __import__(module)
2019-07-08T19:29:05.574242+00:00 app[web.1]: File "/app/flaskapp.py", line 4, in <module>
2019-07-08T19:29:05.574244+00:00 app[web.1]: from pml import app
2019-07-08T19:29:05.574246+00:00 app[web.1]: ModuleNotFoundError: No module named 'pml'
2019-07-08T19:29:05.574494+00:00 app[web.1]: [2019-07-08 19:29:05 +0000] [11] [INFO] Worker exiting (pid: 11)
2019-07-08T19:29:05.682720+00:00 app[web.1]: [2019-07-08 19:29:05 +0000] [4] [INFO] Shutting down: Master
2019-07-08T19:29:05.682883+00:00 app[web.1]: [2019-07-08 19:29:05 +0000] [4] [INFO] Reason: Worker failed to boot.
2019-07-08T19:29:05.849393+00:00 heroku[web.1]: Process exited with status 3
2019-07-08T19:35:15.978510+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=randommovieroulette.herokuapp.com request_id=4e2ad446-cd8a-4136-9875-f94381259b5e fwd="173.71.157.150" dyno= connect= service= status=503 bytes= protocol=https
2019-07-08T19:35:18.311763+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=randommovieroulette.herokuapp.com request_id=154f2f1f-afeb-4765-8e05-1f908fe2d0f4 fwd="173.71.157.150" dyno= connect= service= status=503 bytes= protocol=https

应用程序正在“部署”,但服务器端出现问题。使用我当前的 python 版本创建 runtime.txt 会阻止应用程序部署。那我应该把它改成不同的版本吗?我是新手,如果我犯了一个简单的错误,我深表歉意。

【问题讨论】:

您专注于端口,但这不是问题所在。您的输出显示“ModuleNotFoundError: No module named 'pml'”。你打算依赖this,还是pml 是你自己写的? 已解决!问题是 requirements.txt 它没有我导入的所有包。出于某种原因,它只需要一些包,而不是全部包。非常感谢! 我很高兴你能成功。请考虑answering your own question。 【参考方案1】:

requirements.txt 不包括flask_wtf、bs4、requests 或app,所有这些都是在我的flaskapp.py 文件中导入的。该文件之前只包含 gunicorn 和 gevent。

【讨论】:

以上是关于由于 Error=H10,Flask App 在通过 Heroku 部署时导致应用程序错误的主要内容,如果未能解决你的问题,请参考以下文章

在Docker化Python API / Flask APP时给出pyodbc.Error

Flask and uWSGI - unable to load app 0 (mountpoint='') (callable not found or import error)(

Heroku 崩溃错误:heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/fa

为啥我的 heroku node.js 应用程序给出 at=error code=H10 desc="App crashed" method=GET path="/&qu

python2安装Flask-MySQLdb出现 fatal error C1083: Cannot open include file: 'mysql.h': No su ch fi

flask 中访问时后台错误 error: [Errno 32] Broken pipe