Me again with this error. I do not know what happened, this has been working for a couple of weeks and I have not changed the code (though I did copy and paste it) but all of a sudden this afternoon I am getting this error message: "TypeError: 'NoneType' object is not subscriptable" on line 64 which is this variable: purchase['price'] = currentstock['price']. I get the error after the log in screen.
I understand the error, what I don't understand is why all of a sudden it isn't working when I haven't changed a thing. It was working as of about 2:15pm today. I suppose it is possible when I was copying and pasting I somehow deleted something or moved something. Can someone please help me? I had moved on to sell as this was working and I want to get back on track. I've been stuck on this pset forever, it has been incredibly frustrating and I am at my wit's end with this. I went to the Alphavantage website and there is nothing saying it is down.
@app.route("/") @login_required def index(): """Show portfolio of stocks""" # Once a user makes a purchase they will be redirected to their index page # Edit that to reflect the user's portfolio # Get symbol, shares, cash from databases purchases = db.execute("SELECT symbol, SUM(shares) as sumshares FROM transactions WHERE userid = :userid GROUP BY symbol ORDER BY symbol ASC", userid = session["user_id"]) usercash = db.execute("SELECT cash FROM users WHERE id = :id", id = session["user_id"]) usercash = usercash["cash"] # Declare variable for running total of stock value totalvalstock = 0 # Purchases query will return dicts, loop to iterate over list of dicts. for purchase in purchases: symbol = purchase["symbol"] shares = purchase['sumshares'] currentstock = lookup(purchase['symbol']) purchase['price'] = currentstock['price'] purchase['valbystock'] = purchase['sumshares'] * purchase['price'] totalvalstock += purchase['valbystock'] # calculate total of all stock holdings at their current price and whatever cash the user has left. grandtotal = totalvalstock + usercash # call render_template and pass variables to html template return render_template("index.html", stocks=purchases, usercash=usercash, grandtotal=grandtotal)