我使用Flask构建了一个简单的网站,它在localhost上正常运行。
我是Heroku和Git的新手,我怀疑Procfile可能存在问题。首先,这是我的本地目录树的样子:
我的Procfile包含以下行:
web: gunicorn app:hello
也许我按最后一部分(app:hello)的顺序出问题。不太明白我应该把它放在那里。
我的requirements.txt看起来像这样:
Flask==0.10.1
gunicorn==19.4.1
itsdangerous==0.24
Jinja2==2.8
MarkupSafe==0.23
Werkzeug==0.11.2
要部署应用程序,我使用了以下命令:
heroku login
git init
git add .
git commit -m "First commit"
git push heroku master
最后,这是我的hello.py脚本:
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def home():
return render_template('home.html')
if __name__ == '__main__':
app.run(debug=False)
我现在完全陷入困境,并且不知道如何解决问题。我会很感激任何提示。
更新:我试着查看日志。这是完整的追溯:
D:\Dropbox\Blogs\pythonflasktutorial\myblog>heroku logs
2015-11-27T13:31:21.842599+00:00 app[web.1]: [2015-11-27 13:31:21 +0000] [9] [ER
ROR] Exception in worker process:
2015-11-27T13:31:21.842602+00:00 app[web.1]: Traceback (most recent call last):
2015-11-27T13:31:21.842603+00:00 app[web.1]: File "/app/.heroku/python/lib/pyt
hon2.7/site-packages/gunicorn/arbiter.py", line 515, in spawn_worker
2015-11-27T13:31:21.842604+00:00 app[web.1]: worker.init_process()
2015-11-27T13:31:21.842605+00:00 app[web.1]: File "/app/.heroku/python/lib/pyt
hon2.7/site-packages/gunicorn/workers/base.py", line 122, in init_process
2015-11-27T13:31:21.842606+00:00 app[web.1]: self.load_wsgi()
2015-11-27T13:31:21.842607+00:00 app[web.1]: File "/app/.heroku/python/lib/pyt
hon2.7/site-packages/gunicorn/workers/base.py", line 130, in load_wsgi
2015-11-27T13:31:21.842608+00:00 app[web.1]: File "/app/.heroku/python/lib/pyt
hon2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
2015-11-27T13:31:21.842608+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2015-11-27T13:31:21.842609+00:00 app[web.1]: self.callable = self.load()
2015-11-27T13:31:21.842611+00:00 app[web.1]: return self.load_wsgiapp()
2015-11-27T13:31:21.842610+00:00 app[web.1]: File "/app/.heroku/python/lib/pyt
hon2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
2015-11-27T13:31:21.842612+00:00 app[web.1]: File "/app/.heroku/python/lib/pyt
hon2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
2015-11-27T13:31:21.842614+00:00 app[web.1]: File "/app/.heroku/python/lib/pyt
hon2.7/site-packages/gunicorn/util.py", line 354, in import_app
2015-11-27T13:31:21.842612+00:00 app[web.1]: return util.import_app(self.app
_uri)
2015-11-27T13:31:21.842614+00:00 app[web.1]: __import__(module)
2015-11-27T13:31:21.842615+00:00 app[web.1]: ImportError: No module named app.he
llo
2015-11-27T13:31:21.842616+00:00 app[web.1]: Traceback (most recent call last):
2015-11-27T13:31:21.842616+00:00 app[web.1]: File "/app/.heroku/python/lib/pyt
hon2.7/site-packages/gunicorn/arbiter.py", line 515, in spawn_worker
2015-11-27T13:31:21.842618+00:00 app[web.1]: File "/app/.heroku/python/lib/pyt
hon2.7/site-packages/gunicorn/workers/base.py", line 122, in init_process
2015-11-27T13:31:21.842620+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2015-11-27T13:31:21.842617+00:00 app[web.1]: worker.init_process()
2015-11-27T13:31:21.842619+00:00 app[web.1]: File "/app/.heroku/python/lib/pyt
hon2.7/site-packages/gunicorn/workers/base.py", line 130, in load_wsgi
2015-11-27T13:31:21.842621+00:00 app[web.1]: File "/app/.heroku/python/lib/pyt
hon2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
2015-11-27T13:31:21.842627+00:00 app[web.1]: ImportError: No module named app.he
llo
2015-11-27T13:31:21.842619+00:00 app[web.1]: self.load_wsgi()
2015-11-27T13:31:21.842622+00:00 app[web.1]: File "/app/.heroku/python/lib/pyt
hon2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
2015-11-27T13:31:21.842623+00:00 app[web.1]: return self.load_wsgiapp()
2015-11-27T13:31:21.842625+00:00 app[web.1]: File "/app/.heroku/python/lib/pyt
hon2.7/site-packages/gunicorn/util.py", line 354, in import_app
2015-11-27T13:31:21.842621+00:00 app[web.1]: self.callable = self.load()
2015-11-27T13:31:21.842624+00:00 app[web.1]: File "/app/.heroku/python/lib/pyt
hon2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
2015-11-27T13:31:21.842626+00:00 app[web.1]: __import__(module)
2015-11-27T13:31:21.842625+00:00 app[web.1]: return util.import_app(self.app
_uri)
2015-11-27T13:31:21.891458+00:00 app[web.1]: Traceback (most recent call last):
2015-11-27T13:31:21.842710+00:00 app[web.1]: [2015-11-27 13:31:21 +0000] [9] [IN
FO] Worker exiting (pid: 9)
2015-11-27T13:31:22.999140+00:00 heroku[web.1]: State changed from starting to c
rashed
2015-11-27T13:31:23.000559+00:00 heroku[web.1]: State changed from crashed to st
arting
2015-11-27T13:31:22.990658+00:00 heroku[web.1]: Process exited with status 1
2015-11-27T13:31:25.492194+00:00 heroku[web.1]: Starting process with command `g
unicorn app.hello:app`
2015-11-27T13:31:27.281005+00:00 app[web.1]: [2015-11-27 13:31:27 +0000] [3] [IN
FO] Starting gunicorn 19.4.1
2015-11-27T13:31:27.287796+00:00 app[web.1]: [2015-11-27 13:31:27 +0000] [9] [ER
ROR] Exception in worker process:
2015-11-27T13:31:27.287799+00:00 app[web.1]: Traceback (most recent call last):
2015-11-27T13:31:27.287799+00:00 app[web.1]: File "/app/.heroku/python/lib/pyt
hon2.7/site-packages/gunicorn/arbiter.py", line 515, in spawn_worker
2015-11-27T13:31:27.287800+00:00 app[web.1]: worker.init_process()
2015-11-27T13:31:27.287801+00:00 app[web.1]: File "/app/.heroku/python/lib/pyt
hon2.7/site-packages/gunicorn/workers/base.py", line 122, in init_process
2015-11-27T13:31:27.287801+00:00 app[web.1]: self.load_wsgi()
2015-11-27T13:31:27.287802+00:00 app[web.1]: File "/app/.heroku/python/lib/pyt
hon2.7/site-packages/gunicorn/workers/base.py", line 130, in load_wsgi
2015-11-27T13:31:27.287802+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2015-11-27T13:31:27.287803+00:00 app[web.1]: File "/app/.heroku/python/lib/pyt
hon2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
2015-11-27T13:31:27.287804+00:00 app[web.1]: File "/app/.heroku/python/lib/pyt
hon2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
2015-11-27T13:31:27.287803+00:00 app[web.1]: self.callable = self.load()
2015-11-27T13:31:27.287804+00:00 app[web.1]: return self.load_wsgiapp()
2015-11-27T13:31:27.287805+00:00 app[web.1]: File "/app/.heroku/python/lib/pyt
hon2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
2015-11-27T13:31:27.287805+00:00 app[web.1]: return util.import_app(self.app
_uri)
2015-11-27T13:31:27.287806+00:00 app[web.1]: File "/app/.heroku/python/lib/pyt
hon2.7/site-packages/gunicorn/util.py", line 354, in import_app
2015-11-27T13:31:27.287806+00:00 app[web.1]: __import__(module)
2015-11-27T13:31:27.287807+00:00 app[web.1]: ImportError: No module named app.he
llo
2015-11-27T13:31:27.287807+00:00 app[web.1]: Traceback (most recent call last):
2015-11-27T13:31:27.287807+00:00 app[web.1]: File "/app/.heroku/python/lib/pyt
hon2.7/site-packages/gunicorn/arbiter.py", line 515, in spawn_worker
2015-11-27T13:31:27.287808+00:00 app[web.1]: worker.init_process()
2015-11-27T13:31:27.287808+00:00 app[web.1]: File "/app/.heroku/python/lib/pyt
hon2.7/site-packages/gunicorn/workers/base.py", line 122, in init_process
2015-11-27T13:31:27.287809+00:00 app[web.1]: self.load_wsgi()
2015-11-27T13:31:27.281441+00:00 app[web.1]: [2015-11-27 13:31:27 +0000] [3] [IN
FO] Listening at: http://0.0.0.0:30260 (3)
2015-11-27T13:31:27.281516+00:00 app[web.1]: [2015-11-27 13:31:27 +0000] [3] [IN
FO] Using worker: sync
2015-11-27T13:31:27.286023+00:00 app[web.1]: [2015-11-27 13:31:27 +0000] [9] [IN
FO] Booting worker with pid: 9
2015-11-27T13:31:27.287809+00:00 app[web.1]: File "/app/.heroku/python/lib/pyt
hon2.7/site-packages/gunicorn/workers/base.py", line 130, in load_wsgi
2015-11-27T13:31:27.287809+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2015-11-27T13:31:27.287810+00:00 app[web.1]: File "/app/.heroku/python/lib/pyt
hon2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
2015-11-27T13:31:27.287810+00:00 app[web.1]: self.callable = self.load()
2015-11-27T13:31:27.287810+00:00 app[web.1]: File "/app/.heroku/python/lib/pyt
hon2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
2015-11-27T13:31:27.287811+00:00 app[web.1]: return self.load_wsgiapp()
2015-11-27T13:31:27.287811+00:00 app[web.1]: File "/app/.heroku/python/lib/pyt
hon2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
2015-11-27T13:31:27.287812+00:00 app[web.1]: return util.import_app(self.app
_uri)
2015-11-27T13:31:27.287812+00:00 app[web.1]: File "/app/.heroku/python/lib/pyt
hon2.7/site-packages/gunicorn/util.py", line 354, in import_app
2015-11-27T13:31:27.287812+00:00 app[web.1]: __import__(module)
2015-11-27T13:31:27.287813+00:00 app[web.1]: ImportError: No module named app.he
llo
2015-11-27T13:31:27.287874+00:00 app[web.1]: [2015-11-27 13:31:27 +0000] [9] [IN
FO] Worker exiting (pid: 9)
2015-11-27T13:31:27.302986+00:00 app[web.1]: Traceback (most recent call last):
2015-11-27T13:31:27.302990+00:00 app[web.1]: File "/app/.heroku/python/bin/gun
icorn", line 11, in <module>
2015-11-27T13:31:27.303032+00:00 app[web.1]: File "/app/.heroku/python/lib/pyt
hon2.7/site-packages/gunicorn/app/wsgiapp.py", line 74, in run
2015-11-27T13:31:27.302996+00:00 app[web.1]: sys.exit(run())
2015-11-27T13:31:27.303094+00:00 app[web.1]: WSGIApplication("%(prog)s [OPTI
ONS] [APP_MODULE]").run()
2015-11-27T13:31:27.303108+00:00 app[web.1]: File "/app/.heroku/python/lib/pyt
hon2.7/site-packages/gunicorn/app/base.py", line 192, in run
2015-11-27T13:31:27.303164+00:00 app[web.1]: super(Application, self).run()
2015-11-27T13:31:27.303168+00:00 app[web.1]: File "/app/.heroku/python/lib/pyt
hon2.7/site-packages/gunicorn/app/base.py", line 72, in run
2015-11-27T13:31:27.303207+00:00 app[web.1]: Arbiter(self).run()
2015-11-27T13:31:27.303210+00:00 app[web.1]: File "/app/.heroku/python/lib/pyt
hon2.7/site-packages/gunicorn/arbiter.py", line 179, in run
2015-11-27T13:31:27.303260+00:00 app[web.1]: self.manage_workers()
2015-11-27T13:31:27.303264+00:00 app[web.1]: File "/app/.heroku/python/lib/pyt
hon2.7/site-packages/gunicorn/arbiter.py", line 482, in manage_workers
2015-11-27T13:31:27.303345+00:00 app[web.1]: self.spawn_workers()
2015-11-27T13:31:27.303441+00:00 app[web.1]: File "/app/.heroku/python/lib/pyt
hon2.7/site-packages/gunicorn/arbiter.py", line 219, in handle_chld
2015-11-27T13:31:27.303493+00:00 app[web.1]: self.reap_workers()
2015-11-27T13:31:27.303496+00:00 app[web.1]: File "/app/.heroku/python/lib/pyt
hon2.7/site-packages/gunicorn/arbiter.py", line 464, in reap_workers
2015-11-27T13:31:27.303348+00:00 app[web.1]: File "/app/.heroku/python/lib/pyt
hon2.7/site-packages/gunicorn/arbiter.py", line 549, in spawn_workers
2015-11-27T13:31:27.303576+00:00 app[web.1]: raise HaltServer(reason, self.W
ORKER_BOOT_ERROR)
2015-11-27T13:31:27.303437+00:00 app[web.1]: time.sleep(0.1 * random.random(
))
2015-11-27T13:31:27.303629+00:00 app[web.1]: gunicorn.errors.HaltServer: <HaltSe
rver 'Worker failed to boot.' 3>
2015-11-27T13:31:28.107789+00:00 heroku[web.1]: Process exited with status 1
2015-11-27T13:31:28.126375+00:00 heroku[web.1]: State changed from starting to c
rashed
2015-11-27T13:31:43.565172+00:00 heroku[router]: at=error code=H10 desc="App cra
shed" method=GET path="/" host=pftutorial.herokuapp.com request_id=6b4cf92c-22b1
-4930-a4fa-8c8d51c0e192 fwd="134.0.63.134" dyno= connect= service= status=503 by
tes=
2015-11-27T13:31:44.124825+00:00 heroku[router]: at=error code=H10 desc="App cra
shed" method=GET path="/favicon.ico" host=pftutorial.herokuapp.com request_id=31
8f88ab-88bf-4630-9c86-e3a13e0ebd31 fwd="134.0.63.134" dyno= connect= service= st
atus=503 bytes=
D:\Dropbox\Blogs\pythonflasktutorial\myblog>
答案 0 :(得分:3)
您的Procfile重要性不正确。冒号后面的部分是变量名。
$ gunicorn [OPTIONS] APP_MODULE
您的Procile应该是
web: gunicorn app.hello:app
此外,如果您希望使用Python 3,Heroku要求您指定runtime version。这很重要,因为如果没有__init__.py
文件,Python 2就不会将app视为一个包。