Python Heroku上的Running Flask应用程序
我试图在Heroku上运行一个Flask应用程序,结果令人沮丧。我对老年退休金方面的事情不感兴趣。我只想上传我的代码并让它运行。推送到Heroku git remote可以正常工作(Python Heroku上的Running Flask应用程序,python,sqlite,heroku,flask,peewee,Python,Sqlite,Heroku,Flask,Peewee,我试图在Heroku上运行一个Flask应用程序,结果令人沮丧。我对老年退休金方面的事情不感兴趣。我只想上传我的代码并让它运行。推送到Heroku git remote可以正常工作(git推Heroku master),但是当我跟踪日志(Heroku logs-t)时,我看到以下错误: 2014-11-08T15:48:50+00:00 heroku[slug-compiler]: Slug compilation started 2014-11-08T15:48:58+00:00 heroku
git推Heroku master
),但是当我跟踪日志(Heroku logs-t
)时,我看到以下错误:
2014-11-08T15:48:50+00:00 heroku[slug-compiler]: Slug compilation started
2014-11-08T15:48:58+00:00 heroku[slug-compiler]: Slug compilation finished
2014-11-08T15:48:58.607107+00:00 heroku[api]: Deploy 2ba1345 by <my-email-address>
2014-11-08T15:48:58.607107+00:00 heroku[api]: Release v5 created by <my-email-address>
2014-11-08T15:48:58.723704+00:00 heroku[web.1]: State changed from crashed to starting
2014-11-08T15:49:01.458713+00:00 heroku[web.1]: Starting process with command `gunicorn app:app`
2014-11-08T15:49:02.538539+00:00 app[web.1]: bash: gunicorn: command not found
2014-11-08T15:49:03.340833+00:00 heroku[web.1]: Process exited with status 127
2014-11-08T15:49:03.355031+00:00 heroku[web.1]: State changed from starting to crashed
2014-11-08T15:49:04.462248+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=blueprnt.herokuapp.com request_id=e7f92595-b202-4cdb-abbc-309dcd3a04bc fwd="54.163.35.91" dyno= connect= service= status=503 bytes=
requirements.txt
Flask==0.10.1
Flask-Login==0.2.11
Flask-WTF==0.10.2
Jinja2==2.7.3
MarkupSafe==0.23
Unidecode==0.04.16
WTForms==2.0.1
Werkzeug==0.9.6
awesome-slugify==1.6
blinker==1.3
gnureadline==6.3.3
gunicorn==19.1.1
ipdb==0.8
ipython==2.3.0
itsdangerous==0.24
peewee==2.4.0
py-bcrypt==0.4
pytz==2014.7
regex==2014.10.24
wsgiref==0.1.2
wtf-peewee==0.2.3
app.py(跑步部分)
我已经尝试了来自和来自两个方面的答案。当我尝试向Heroku施压进行调查(Heroku run bash
)时,我的应用程序环境似乎有问题:
(blueprnt)☀ website [master] heroku run bash
/Users/andymatthews/.rvm/gems/ruby-1.9.3-p125/gems/heroku-3.15.0/lib/heroku/helpers.rb:91: warning: Insecure world writable dir /usr/local in PATH, mode 040777
Running `bash` attached to terminal... up, run.8540
~ $ ls
Gruntfile.js __init__.py fixtures models.py requirements.txt static vendor
Procfile app.py forms.py node_modules settings.py templates views
README.md blueprnt.db mixins.py package.json site-theme-assets.zip utils.py
~ $ pwd
/app
~ $ whoami
u15880
~ $ which pip
~ $ which git
/usr/bin/git
~ $ pip install -r requirements.txt
bash: pip: command not found
我真的很想得到一些帮助。在过去,当我将应用程序部署到Heroku时,我没有遇到任何问题。但这个应用程序比其他应用程序更复杂。这不是答案,但必须包含一个相当大的代码块 当前回溯的部分问题在于它并没有真正为调试提供相关信息。您可以在heroku上记录错误,然后使用
heroku日志
对您的应用程序的错误进行更深入的追踪
为此,请在app.logger
上添加一个处理程序。Heroku将从sys.stderr
中提取数据,因此您可以使用logging.StreamHandler
类
import logging
import sys
from logging import Formatter
def log_to_stderr(app):
handler = logging.StreamHandler(sys.stderr)
handler.setFormatter(Formatter(
'%(asctime)s %(levelname)s: %(message)s '
'[in %(pathname)s:%(lineno)d]'
))
handler.setLevel(logging.WARNING)
app.logger.addHandler(handler)
if __name__ == '__main__':
log_to_stderr(app)
app.run()
您似乎没有将
app
导入app.py
。这只是一个遗漏吗?您可以尝试重新部署它,只需删除该应用程序,然后按照中所述的步骤重新创建它。您是否专门将Heroku项目设置为使用Python?如果没有,Heroku会将包含package.json
的项目设置到节点buildpack。请查看更多详细信息和解决方案(如果这确实是您的问题)。@jonfato,这就是问题所在。由于package.json文件,Heroku认为这是一个节点项目。我明确地设置了buildpack\uURL,效果非常好。如果你能给出一个真实的答案,我很乐意选择它。
(blueprnt)☀ website [master] heroku run bash
/Users/andymatthews/.rvm/gems/ruby-1.9.3-p125/gems/heroku-3.15.0/lib/heroku/helpers.rb:91: warning: Insecure world writable dir /usr/local in PATH, mode 040777
Running `bash` attached to terminal... up, run.8540
~ $ ls
Gruntfile.js __init__.py fixtures models.py requirements.txt static vendor
Procfile app.py forms.py node_modules settings.py templates views
README.md blueprnt.db mixins.py package.json site-theme-assets.zip utils.py
~ $ pwd
/app
~ $ whoami
u15880
~ $ which pip
~ $ which git
/usr/bin/git
~ $ pip install -r requirements.txt
bash: pip: command not found
import logging
import sys
from logging import Formatter
def log_to_stderr(app):
handler = logging.StreamHandler(sys.stderr)
handler.setFormatter(Formatter(
'%(asctime)s %(levelname)s: %(message)s '
'[in %(pathname)s:%(lineno)d]'
))
handler.setLevel(logging.WARNING)
app.logger.addHandler(handler)
if __name__ == '__main__':
log_to_stderr(app)
app.run()