title: TypeError: hash must be unicode or bytes, not builtin_function_or_method
body: <p>I am trying to implement <strong>JWT</strong> authorization to a Flask app. However when I try to login, It returns a <code>"500 Internal server error"</code> with a "TypeError: hash must be unicode or bytes, not builtin_function_or_method". What could I be missing out here.</p>
  
  <p><strong><em>Here is my class from models.py</em></strong></p>
  
  <pre><code>from passlib.hash import pbkdf2_sha256
  
  # Create classes to store data.
  class User:
  """ This class provides a way to store user data. """
  
      users = [
          {
              'id': 1,
              'username': u'mwinel',
              'email': u'mwinel@example.com',
              'password': u'code618'
          },
          {
              'id': 2,
              'username': u'lucy',
              'email': u'lucy@example.com',
              'password': u'123456'
          }
      ]
  
      def __init__(self, id, username, email, password):
          """ Initialize objects. """
          self.id = user_id,
          self.username = username,
          self.email = email,
          self.password = password
  
      @staticmethod
      # Generate a hashed string to be
      # stored by our class model.
      def generate_hash(password):
          hash = pbkdf2_sha256.encrypt(password, rounds = 20000, salt_size = 16)
          return hash
  
      @staticmethod
      # Check a given password.
      def verify_hash(password, hash):
          return pbkdf2_sha256.verify(password, hash)
  </code></pre>
  
  <p><strong><em>And here is my login method</em></strong></p>
  
  <pre><code>from flask_restful import Resource, reqparse
  from app.models import User
  
  class UserLogin(Resource):
      # Call the method to login a user.
      def post(self):
          parser = reqparse.RequestParser()
          parser.add_argument('username', required = True)
          parser.add_argument('password', required = True)
  
          data = parser.parse_args()
          username = data['username']
          password = data['password']
          for user in User.users:
              if password == User.verify_hash(data['password'], hash):
                  return {
                      'message': 'Logged in as {}'.format(data['username']),
                  }, 200
          return {
              'message': 'Something went wrong'
          }, 500
  </code></pre>
  
  <p><strong><em>And here is the error</em></strong></p>
  
  <pre><code>TypeError: hash must be unicode or bytes, not builtin_function_or_method
  </code></pre>