2016-09-25 118 views
1

我有一個使用瓶,登錄身份驗證的應用程序燒瓶。一切工作正常本地都使用燒瓶內置的Web服務器和gunicorn本地運行。但是,當它在heroku上時,它有問題,有時會讓我登錄,有時它不會。當我在導航會話的幾秒鐘內成功登錄時,只會被破壞並讓我自動登出。這應該發生在用戶註銷時。Heroku的gunicorn燒瓶登錄工作不正常

在我看來,下面的代碼片段可能是相關的:

@app.before_request 
def before_request(): 
    g.user = current_user 

# I have index (/) and other views (/new) decorated with @login_required 

我可能會遇到類似問題with this。它沒有任何解答,從我從評論看,筆者只跑了他的應用程序與python app.py。這是通過使用燒瓶內置的Web服務器。不過,我似乎無法複製他的解決辦法,因爲運行app.run(host='0.0.0.0')運行在端口5000的應用程序,我似乎無法設置port=80因爲權限。

我沒有看到任何與日誌有幫助,只是它甚至沒有時,我應該進行身份驗證。

一部分,當我得到了驗證,並試圖轉到/new/交替,直到它記錄了我從日誌:

2016-09-25T06:57:53.052378+00:00 app[web.1]: authenticated - IP:10.179.239.229 
2016-09-25T06:57:53.455145+00:00 heroku[router]: at=info method=GET path="/" host=testdep0.herokuapp.com request_id=c7c8f4c9-b003-446e-92d8-af0a81985e72 fwd="124.100.201.61" dyno=web.1 connect=0ms service=116ms status=200 bytes=6526 
2016-09-25T06:58:11.415837+00:00 heroku[router]: at=info method=GET path="/new" host=testdep0.herokuapp.com request_id=ae5e4e29-0345-4a09-90c4-36fb64785079 fwd="124.100.201.61" dyno=web.1 connect=0ms service=7ms status=200 bytes=2552 
2016-09-25T06:58:13.543098+00:00 heroku[router]: at=info method=GET path="/" host=testdep0.herokuapp.com request_id=47696ab9-57b9-4f20-810a-66033e3e9e50 fwd="124.100.201.61" dyno=web.1 connect=0ms service=8ms status=200 bytes=5982 
2016-09-25T06:58:18.037766+00:00 heroku[router]: at=info method=GET path="/new" host=testdep0.herokuapp.com request_id=98912601-6342-4d71-a106-26056e4bbb21 fwd="124.100.201.61" dyno=web.1 connect=0ms service=3ms status=200 bytes=2552 
2016-09-25T06:58:19.619369+00:00 heroku[router]: at=info method=GET path="/" host=testdep0.herokuapp.com request_id=2b04d31f-93a2-4653-83a4-f95ca9b97149 fwd="124.100.201.61" dyno=web.1 connect=0ms service=3ms status=302 bytes=640 
2016-09-25T06:58:19.953910+00:00 heroku[router]: at=info method=GET path="/login?next=%2F" host=testdep0.herokuapp.com request_id=e80d15cd-e9ad-45ff-ae54-e156412fe4ff fwd="124.100.201.61" dyno=web.1 connect=0ms service=3ms status=200 bytes=2793 

Procfile:

web: gunicorn app:app

回答

1

的問題要解決增加了對gunicorn的--preload選項。我不完全確定如何解決這個問題,如果有人能解釋,我會很感激。

更新Procfile:

web: gunicorn app:app --preload

0

跟進什麼krato說(這得到它的工作,在所有),我的應用程序還沒有完美的工作。即使它第一次登錄,我可以保持清爽,最終會被註銷。所以閱讀this article後我設置gunicorn只使用1工人像這樣:

網站:gunicorn -w 1:應用--preload

這似乎這樣的伎倆。