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.

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[0]["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) 
  • Hard to help you, as lookup might just have failed to look up the symbol (because of API fail, like too many API requests for that key) and returned None because of that.
    – Blauelf
    Jul 18, 2018 at 8:20

1 Answer 1


It sounds like it is a problem with the API. I hardcoded a value for price in the helpers file and everything is working again. I must have exceeded my quota, I will use the hardcoded values until the rest of the functions are built and then revert the code. Thanks for your help as always.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .