2014-11-08 171 views
0

我試圖在Heroku上運行Flask應用程序,我得到了一些令人沮喪的結果。我對事物的操作方面不感興趣。我只想上傳我的代碼並讓它運行。推到Heroku的git的遠程工作正常(git push heroku master),但是當我尾部日誌(heroku logs -t)我看到了以下錯誤:在Heroku上運行Flask應用程序

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= 

這裏的相關文件:

Procfile

web: gunicorn app:app 
heroku ps:scale web 

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(運行部分)

# 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) 

我從this threadthis thread試用過的答案。當我嘗試到外殼的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時,我沒有任何問題。但是這個應用程序比其他應用程序更復雜。

+0

你似乎沒有導入'app'成'app.py'。這只是一種遺漏嗎? – dirn 2014-11-08 16:31:45

+0

您可以嘗試重新部署它,只需刪除該應用程序,然後按照https://devcenter.heroku.com/articles/getting-started-with-python#introduction中所述的步驟重新制作該應用程序 – 2014-11-08 22:47:32

+0

您是否專門設置了您的Heroku項目使用Python?如果沒有,Heroku將包含'package.json'的項目設置爲節點buildpack。請參閱[這個答案](https://stackoverflow.com/questions/20171169/why-is-my-flask-app-being-detected-as-node-js-on-heroku/20171188#20171188)瞭解更多詳情和一個解決方案(如果這確實是你的問題)。 – jonafato 2014-11-09 20:01:40

回答

1

這不是一個答案,但必須包括一個體面的大小代碼塊中的問題與當前的回溯是它並沒有真正爲調試提供相關信息

部分。您可以在heroku上記錄這些錯誤,然後使用heroku log來獲得應用程序錯誤的更多實質追蹤。

通過在您的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() 
相關問題