2016-03-07 67 views
0

我遇到一個500內部服務器錯誤在我DELETE DEF:Python的燒瓶刪除500內部服務器錯誤

def delete(self, flight_id): 
    session = db.get_session() 
    try: 
     spend_for_flight = session.query(func.count(db.Snapshot.rowID))\ 
      .join(db.Flight, db.Flight.strategy_id == db.Snapshot.strategy_id)\ 
      .filter(and_(db.Snapshot.interval >= db.Flight.start_date, db.Snapshot.interval <= db.Flight.end_date, db.Flight.rowID == flight_id)).scalar(); 

     # there is spend for at least one of these flight dates 
     if spend_for_flight > 0: 
      response = jsonify(error="Flight has spend. Cannot delete.") 
      response.status = 400 
      return response 
     elif spend_for_flight == 0: 
      session.query(db.Flight).filter(db.Flight.rowID == flight_id).delete() 
      session.commit() 
      return 204 
    except sqlalchemy.exc.SQLAlchemyError, exc: 
     session.rollback() 
     reason = exc.message 
     response = jsonify(error=reason) 
     response.status_code = 501 
     return response 
    finally: 
     session.close() 

誤差在if語句發生。 SQL鍊金術查詢運行正常,並且spend_for_flight檢出(其他成功),並且航班成功刪除。當spend_for_flight >0,我得到服務器錯誤。

感謝

+1

調試500錯誤的第一步是在調試模式下運行,所以你可以看到回溯。 'app.run(debug = True)' – davidism

回答

1

像你與501你應該使用status_code而不是status。也就是說,不是,:

response.status = 400 

response.status_code = 400 
+0

這樣做,謝謝你的第二雙眼睛 – Alex