title: Where is the "The view function did not return a valid response." error in my Flask app?
body: <p>I have a flask app that adds User data to a MySQL database. Everything on my script seems to work fine. The data I want is getting added to the MySQL database. However I'm getting the following error:</p>
  
  <pre><code>127.0.0.1 - - [28/Jun/2018 12:19:44] "GET /protected HTTP/1.1" 500 -
  Traceback (most recent call last):
    File "/Users/open/venv/FlaskMiddleware/lib/python2.7/site-packages/flask/app.py", line 2309, in __call__
      return self.wsgi_app(environ, start_response)
    File "/Users/open/venv/FlaskMiddleware/lib/python2.7/site-packages/flask/app.py", line 2295, in wsgi_app
      response = self.handle_exception(e)
    File "/Users/open/venv/FlaskMiddleware/lib/python2.7/site-packages/flask_restful/__init__.py", line 273, in error_router
      return original_handler(e)
    File "/Users/open/venv/FlaskMiddleware/lib/python2.7/site-packages/flask/app.py", line 1741, in handle_exception
      reraise(exc_type, exc_value, tb)
    File "/Users/open/venv/FlaskMiddleware/lib/python2.7/site-packages/flask/app.py", line 2292, in wsgi_app
      response = self.full_dispatch_request()
    File "/Users/open/venv/FlaskMiddleware/lib/python2.7/site-packages/flask/app.py", line 1816, in full_dispatch_request
      return self.finalize_request(rv)
    File "/Users/open/venv/FlaskMiddleware/lib/python2.7/site-packages/flask/app.py", line 1831, in finalize_request
      response = self.make_response(rv)
    File "/Users/open/venv/FlaskMiddleware/lib/python2.7/site-packages/flask/app.py", line 1957, in make_response
      'The view function did not return a valid response. The'
  TypeError: The view function did not return a valid response. The function either returned None or ended without a return statement.
  </code></pre>
  
  <p>I cant really figure out why I'm getting this error.</p>
  
  <p>This is my code:</p>
  
  <pre><code>from flask import Flask, request, jsonify, session
  from flask_restful import Resource, Api
  from werkzeug.security import generate_password_hash, check_password_hash
  import mysqldb
  from flask_jwt_extended import (
      JWTManager, jwt_required, create_access_token,
      get_jwt_identity
  )
  
  
  app = Flask(__name__)
  app.config['SECRET_KEY'] = 'super-secret'
  jwt = JWTManager(app)
  
  api = Api(app, prefix="/api/v1")
  
  USER_DATA = {
      "user1": "abc123",
      "user2":"userpass"
  }
  
  @app.route('/login', methods=['POST'])
  def login():
      if not request.is_json:
          return jsonify({"msg": "Missing JSON in request"}), 400
  
      username = request.json.get('username', None)
      password = request.json.get('password', None)
      if not username:
          return jsonify({"msg": "Missing username parameter"}), 400
      if not password:
          return jsonify({"msg": "Missing password parameter"}), 400
  
      if username != USER_DATA.get(username) and password not in USER_DATA[username]:
          return jsonify({"msg": "Bad username or password"}), 401
  
      access_token = create_access_token({'first_name': request.json.get('Client First Name', None), 'last_name': request.json.get('Client Last Name', None)})
      return jsonify(access_token=access_token), 200
  
  class PrivateResource(Resource):
      @app.route('/protected', methods=['GET'])
      @jwt_required
  
      def sendData():
          data = get_jwt_identity()
          return mysqldb.addUser("{}".format(str(data['first_name'])),"{}".format(str(data['last_name'])))
  
  
  
  if __name__ == '__main__':
      app.run(debug=True)
  </code></pre>
  
  <p>The <code>addUser</code> function is this:</p>
  
  <pre><code>def addUser(Fname,Lname):
      try:
          cursorObject = connection.cursor()
          cursorObject.execute("call sp_createUser('{}'".format(Fname)+",'{}')".format(Lname))
          connection.commit()
          connection.close()
  
      finally:
          print('User data added succesfully!')
  </code></pre>
  
  <p>What is wrong in my code that causes the error?</p>