Search code examples
financecs50

CS50 Finance KeyError


Nomatter what I do, I keep getting issues with a Keyerror on my /buy.

db.execute("INSERT INTO transactions (ticker, shares, price, id, transaction) VALUES(:ticker, :shares, :price, :id, :transaction)", ticker=stock["ticker"], shares=shares, price=stock["price"], id=session["user_id"], transaction=now)

I keep getting the error message: KeyError: 'ticker'


Solution

  • Probably complaining about ticker=stock["ticker"]. I'm going out on a limb and suspect you want stock['symbol'], with the assumption that the stock array is built from lookup. If that's not the case, you'll need to edit the question to include more code, especially where stock['ticker'] gets populated in relation to the insert.