title: Python Sqlite3 TypeError: 'NoneType' object is not subscriptable
body: <pre class="lang-py prettyprint-override"><code>def get_coffee_name(coffee_type):
      if coffee_type == "Hot":
          conn = sqlite3.connect('coffee.db')
          c = conn.cursor()
          coffee_id = rand_coffee()
          c.execute("SELECT tag FROM coffees WHERE id = '%s'" % (coffee_id))
          while True:
              coffee_type = c.fetchone()[0]
              print(coffee_type)
              if coffee_type == "Hot":
                  conn.close()
                  conn = sqlite3.connect('coffee.db')
                  c = conn.cursor()
                  c.execute("SELECT name FROM coffees WHERE id = '%s'" % (coffee_id))
                  return c.fetchone()[0]
                  break
  </code></pre>
  
  <p>Returns</p>
  
  <pre class="lang-py prettyprint-override"><code>TypeError: 'NoneType' object is not subscriptable
  </code></pre>
  
  <p>I tried other solutions for loop but it didn't worked that way too.</p>
  
  <p><code>coffee_type</code> is Cold or Hot and not none at all times.</p>