I cannot figure this one out, no matter what I do. I keep getting the Unexpected Indent Error, no matter what I do with the spacing.
I've spent two days trying to fix it myself and find someone who can explain what is going on. I have included a screenshot of my CS50 IDE because I feel that it best shows the error I am having.
@app.route("/sell", methods=["GET", "POST"])
@login_required
def sell():
if request.method == "POST":
quote = lookup(request.form.get("symbol"))
if quote == None:
return apology ("invalid symbol", 400)
try:
shares = int(request.form.get("shares"))
except:
return apology("shares must be positive", 400)
You need to 'close' the try
block with a except
, i.e:
try:
shares = (int(request.form.get("shares"))
except Exception as err:
print(err)
Or skip the try
, and use try-except when you know what type of error to expect, i.e:
shares = (int(request.form.get("shares"))
More information on try-except blocks is here.
So the error about indentation is misleading. I have been there too :(