active = User.select().where(User.active == True)try: user = active.where(User.username == request.form['username']).get()except User.DoesNotExist: return make_response(jsonify({'error': 'Bad request'}), 400)else: if not user.check_password(...)