Python flask delete 500 internal server error -


i'm running 500 internal server error in delete def:

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 spend @ least 1 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() 

the error happening in if statement. sql alchemy query runs fine , spend_for_flight checks out (the else succeeds) , flight deletes successfully. when spend_for_flight >0, server error.

thanks

you should use status_code instead of status did 501. is, instead of:

response.status = 400 

write

response.status_code = 400 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

python - pip wont install .WHL files -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -