0

I have been trying to debug this for the past three hours but I can't find anything to save my life @app.route("/buy", methods=["GET", "POST"]) @login_required def buy(): """Buy shares of stock"""

if request.method == "POST":

    #Get information from form fields
    name = request.form.get("name")
    num = request.form.get("quantity")


    #Validating input
    if not name:
        return apology("Field must not be left blank")
    elif not num:
        return apology("Field must not be left blank")
    elif (num <= 0):
        return apology("Quantity must be positive")

    #Getting stock information from the API
    quote = lookup(name)

    if not quote:
        return apology("Stock Name not Valid")

    #Getting users info from the database
    cash = db.execute("SELECT cash FROM users WHERE id = :id", id = session["user_id"])


    #Check if the user can afford the stock
    if (quote["price"] * num) > cash[0]:
        return apology("You can't afford the stock")

else:
    return render_template("buy.html")

Error traceback:

ERROR:werkzeug:Error on request:

Traceback (most recent call last): File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/werkzeug/serving.py", line 270, in run_wsgi execute(self.server.app) File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/werkzeug/serving.py", line 258, in execute application_iter = app(environ, start_response) File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/flask/app.py", line 2309, in call return self.wsgi_app(environ, start_response) File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/flask/app.py", line 2295, in wsgi_app response = self.handle_exception(e) File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/flask/app.py", line 1748, in handle_exception return self.finalize_request(handler(e), from_error_handler=True) File "/home/ubuntu/workspace/pset7/finance/application.py", line 216, in errorhandler return apology(e.name, e.code) AttributeError: 'TypeError' object has no attribute 'name'

1

Look in the flask log again. For some reason any error from flask is always followed by the one from errorhandler that you show here, which starts with ERROR:werkzeug:Error on request:. Go backwards in the log and you are bound to see a ERROR:flask.app:Exception. That is the error you need to worry about.

You must log in to answer this question.

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