2015-02-07 233 views
0

我建立了學習的目的與瓶-SQLAlchemy的,並部署在Heroku(蟒蛇/ PostgreSQL的一個小系統:500內部服務器錯誤的Heroku

http://monkey-me.herokuapp.com/

https://github.com/coolcatDev/monkey-me

我的應用程序工作正常,局部和我已經通過14個測試成功通過了單元測試其功能和用例。

當我部署一切似乎完美。它的部署,我定義的環境變量APP_SETTING S >>> config.BaseConfig,我運行db_create.py腳本來初始化數據庫。我創建一些用戶:

username-userpassword: 

Alex-passwordAlex 
Jack-passwordJack 
Sara-passwordSara 

但有一件事是失蹤...我去從主導航欄中的用戶頁面,我得到一個5OO內部服務器錯誤說:

The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application. 

我的應用程序app.py上的代碼具有調試模式:

if __name__ == '__main__': 
app.run(debug=True) 

但是不顯示更多錯誤。

注意,如果我訪問在Heroku上的系統,我退出,如果我去的用戶,我,我應該重定向到登錄頁面,因此多數民衆贊成我已經走了多遠與調試...

如果我在heroku上設置環境變量LAUNCHY_DEBUG爲真或假,一切都會變得瘋狂並出現新問題...就像我無法刪除用戶,配置文件圖像不會加載....

如果我刪除LAUNCHY_DEBUG var從heroku新的問題(圖像不會加載,不能刪除用戶..)持續在用戶頁面的原始500錯誤。

預先感謝與調試

+0

您正在使用gunicorn。這意味着您不要在調試模式下啓動開發服務器。這很好。但這意味着您需要檢查日誌以查看錯誤是什麼。 – dirn 2015-02-07 14:40:08

+0

@dirn感謝您的評論。我對heroku很陌生,所以我非常有限。我用「heroku logs -n 1500」檢查日誌。與顯示錯誤的用戶頁面匹配請求的日誌僅顯示: – 2015-02-07 15:06:56

+0

2015-02-07T14:01:05.297748 + 00:00 heroku [router]:at = info method = GET path =「/ users」host = monkey -me.herokuapp.com request_id = 2ff807e8-7f4a-4427-ba26-6301fb541a73 fwd =「31.46.53.207」dyno = web.1 connect = 1ms service = 44ms status = 500 bytes = 456 – 2015-02-07 15:07:17

回答

4

使用以下方法來獲得更多的反饋寫在日誌中的任何建議:

import logging 

app.logger.addHandler(logging.StreamHandler(sys.stdout)) 
app.logger.setLevel(logging.ERROR) 

,揭示了問題:

ProgrammingError: (ProgrammingError) column "user_bf.id" must appear in the GROUP BY clause or be used in an aggregate function 

修改查詢:

userList = (
      users.query 
      .add_column(db.func.count(friendships.user_id).label("total")) 
      .add_column(user_bf.id.label("best_friend")) 
      .add_column(user_bf.userName.label("best_friend_name")) 
      .outerjoin(friendships, users.id == friendships.user_id) 
      .outerjoin(user_bf, users.best_friend) 
      .group_by(users.id, user_bf.id) 
      .order_by(test) 
      .paginate(page, 6, False) 
     ) 

關於圖像消失:

任何寫在託管在heroku上的文件系統上的文件都將在dynos生命週期結束時被刪除。