In the "buy" function of applications.py, no matter what I type, the CS50 IDE and flask both say I have a syntax error in my program. I don't see it and have tried removing parts, checked the syntax many many times and still can't see why the program crashes every time. I have part of the buy function from pset7 and the error message below:(The db.execute line is all on one line in my actual program, this website just butchered the formatting)

> @app.route("/buy", methods=["GET", "POST"]) @login_required def buy():
>     if request.method == "POST":
>         if not request.form.get("symbol"):
>             return apology("Must enter a stock symbol")
>         elif not request.form.get("shares"):
>             return apology("Must enter number of shares")
>         stock = request.form.get("symbol")
>         rows = db.execute("SELECT * FROM users WHERE id = :user_id", user_id=session["user_id"])
>         cash = rows[0]['cash']
>         quotes = lookup(stock)
>         shares = int(request.form.get("shares"))
>         tot_price = int(quotes['price']) * shares
>         if quotes == None:
>             return apology("Stock doesn't exist")
>         if cash < tot_price:
>             return apology("You don't have enough cash")
>         db.execute("INSERT INTO transactions (user_id, stock, shares, price, date) VALUES(:id, :stock, :shares, :price, :date)", id =
> session["user_id"], stock=stock, shares=shares ,
> price=int(quotes['price'], date=datetime.datetime.now())
>     else:
>         return render_template("buy.html")

Error Message

1 Answer 1


Unless it is some paste problem, there's a missing close ) on the db.execute line.

You must log in to answer this question.

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