I'm working on pset7 index, and I've hit a snag. When I try to log in and render index, I get this error:
TypeError: 'NoneType' object is not subscriptable
It says the main error is on line 50:
name = stock["name"]
Here is my code:
@app.route("/") @login_required def index(): #get users current stocks holdings = db.execute("SELECT shares, symbol FROM history WHERE id = :id", id=session["user_id"]) #set placeholder for total cash value (cash + holdings) cash = db.execute("SELECT cash FROM users WHERE id=:id", id=session["user_id"]) cash = cash["cash"] total_cash = cash #get shares owned, current price, and total value of each holding for holding in holdings: symbol = holding["symbol"] shares = holding["shares"] stock = lookup(symbol) name = stock["name"] current_price = stock["price"] total = current_price * shares total_cash += shares * current_price #render template return render_template("index.html", stocks=holdings, cash=usd(cash), total=usd(total_cash))
I'm guessing that the main problem is that symbol is returning a Nonetype, which means that the holdings variable isn't selecting properly. Does anyone have any ideas? Thank you.