title: TypeError: coercing to Unicode: need string or buffer, sqlite3.Cursor found
body: <p>I am building a Python web app using Flask and SQLite as the DB. </p>
  
  <p>I get the above error when I attempt to login and validate user info from the database. My other database form inputs work and I am able to update and select data, so the database exists and the connection works in some parts of the app. The login script seems to be the issue.</p>
  
  <pre><code>@app.route('/login', methods=['POST', 'GET'])
  def do_admin_login():
  if request.method == "POST":
  u_stmt="SELECT CASE WHEN '"+ request.form['username'] +"' IN (SELECT uname 
  FROM logins) THEN 1 ELSE 0 END"  #uname in logins
  p_stmt="SELECT pword FROM logins WHERE uname = '"+request.form['username']+"'"  
  # retrieve pwd of uname
  s_stmt="SELECT salt FROM logins WHERE uname = '"+request.form['username']+"'"  
  # retrieve salt of uname
  print u_stmt
  print p_stmt
  print s_stmt
  with sql.connect("database.db") as con:
    cur = con.cursor()
    pwd = cur.execute(p_stmt)
    uname = cur.execute(u_stmt)
    salt = cur.execute(s_stmt)
    print uname
    print pwd
    print salt
    con.commit()
  con.close()
  
  hashed_password = hash_password(request.form['password'], salt)
  if hashed_password == pwd and uname == 1:
      session['logged_in'] = True     
      flash('right password!')
      return render_template('home.html')
  else:
      flash('wrong password!')
  return home()
  else:
  return render_template('login.html')
  </code></pre>
  
  <p>Here is the code from my login.html</p>
  
  <pre><code>&lt;form action="/login" method="POST"&gt;
  &lt;div class="login"&gt;
      &lt;div class="login-screen"&gt;
          &lt;div class="app-title"&gt;
              &lt;h1&gt;Login&lt;/h1&gt;
          &lt;/div&gt;
  
          &lt;div class="login-form"&gt;
              &lt;div class="control-group"&gt;
              &lt;input type="text" class="login-field" value="" placeholder="username" name="username"&gt;
              &lt;label class="login-field-icon fui-user" for="login-name"&gt;&lt;/label&gt;
              &lt;/div&gt;
  
              &lt;div class="control-group"&gt;
              &lt;input type="password" class="login-field" value="" placeholder="password" name="password"&gt;
              &lt;label class="login-field-icon fui-lock" for="login-pass"&gt;&lt;/label&gt;
              &lt;/div&gt;
  
              &lt;button type="submit" class="btn btn-primary btn-large btn-block"&gt;Log in&lt;/button&gt;
              &lt;br&gt;&lt;br&gt;
              &lt;a href="signup" class="btn btn-primary btn-large btn-block"&gt;Sign up&lt;/a&gt;
              &lt;br&gt;&lt;br&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p></p>
  
  <p><a href="https://i.stack.imgur.com/g79uv.png" rel="nofollow noreferrer">Stacktrace (methinks)</a></p>
  
  <p>Any help is greatly appreciated. Thank you!</p>
  
  <pre><code>def hash_password(password, salt):
  """
  Take a password and a salt, and return a hashed password
  """
  password_string = (password + salt).encode('utf-8')
  hashed_password = hashlib.sha512(password_string).hexdigest()
  return hashed_password
  
  
  def get_auth_for_user(user_id):
  """
  Take a user_id, and return what we know about that user
  """
  db_cursor.execute("SELECT * FROM user WHERE id=" + user_id)
  result = db_cursor.fetchone()
  return result
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/Dg9lp.png" rel="nofollow noreferrer">Traceback with SQL output</a></p>