简体   繁体   English

在Heroku上运行Flask应用

[英]Running Flask app on Heroku

I'm trying to run a Flask app on Heroku and I'm getting some frustrating results. 我试图在Heroku上运行Flask应用,但结果却令人沮丧。 I'm not interested in the ops side of things. 我对操作的方面不感兴趣。 I just want to upload my code and have it run. 我只想上传我的代码并运行它。 Pushing to the Heroku git remote works fine ( git push heroku master ), but when I tail the logs ( heroku logs -t ) I see the following error: 推送到Heroku git远程工作正常( git push 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=

Here's the pertinent files: 以下是相关文件:

Procfile Procfile

web: gunicorn app:app
heroku ps:scale web

requirements.txt 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 (the run portion) app.py(运行部分)

# Run application
if __name__ == '__main__':
    # from os import environs
    # app.run(debug=False, port=environ.get("PORT", 5000), processes=2)
    app.run(debug=True, port=33507)

I've tried both the answer from this thread and from this thread . 我已经尝试了这个线程这个线程的答案。 When I try to shell into Heroku to investigate ( heroku run bash ) it appears that something is wrong with my app's environment: 当我尝试使用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

Would really love some assistance. 真的会喜欢一些帮助。 In the past when I've deployed apps to Heroku, I haven't had any problem. 过去,当我将应用程序部署到Heroku时,我没有遇到任何问题。 But this app is more complicated than those others. 但是,此应用比其他应用更为复杂。

this isn't an answer but had to include a decent sized code block 这不是答案,但必须包含一个适当大小的代码块

Part of the problem with your current traceback is it does not really provide relevant information for debugging. 当前回溯的部分问题在于它实际上并未提供调试所需的相关信息。 You can log the errors on heroku then use heroku log to get a more substantial traceback of your app's errors. 您可以将错误记录在heroku上,然后使用heroku log对应用程序的错误进行更详细的追溯。

Do this by adding a handler on to your app.logger . 为此,可以在app.logger上添加一个处理程序。 Heroku will pick up data from sys.stderr so you can use a logging.StreamHandler class 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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM