0

code:

def index():
    """Show portfolio of stocks"""
    portfolio_symbols = db.execute("SELECT shares, symbol \
                                    FROM log WHERE id = :id", \
                                    id=session["user_id"])

    # create a temporary variable to store TOTAL worth ( cash + share)
    total = 0
    total1 = 0

    # update each symbol prices and total
    for portfolio_symbol in portfolio_symbols:

        shares = portfolio_symbol["shares"]
        symbol = portfolio_symbol["symbol"]
        symbol = lookup(symbol)
        total1 = shares * symbol["price"]
        total += total1
        db.execute("UPDATE log SET price=:price, \
                    total=:total WHERE id=:id AND symbol=:symbol", \
                    price=usd(symbol["price"]), \
                    total=usd(total1), id=session["user_id"], symbol=symbol)

    # update user's cash in portfolio
    updated_cash = db.execute("SELECT cash FROM users \
                               WHERE id=:id", id=session["user_id"])

    # update total cash -> cash + shares worth
    total += updated_cash[0]["cash"]

    # print portfolio in index homepage
    updated_portfolio = db.execute("SELECT * from log \
                                    WHERE id=:id", id=session["user_id"])

    return render_template("index.html", stocks=updated_portfolio, \
                            cash=usd(updated_cash[0]["cash"]), total1= usd(total) )

terminal :

**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 1997, 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 1985, in wsgi_app
    response = self.handle_exception(e)
  File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/flask/app.py", line 1540, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/flask/app.py", line 1982, in wsgi_app
    response = self.full_dispatch_request()
  File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/flask/app.py", line 1614, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/flask/app.py", line 1517, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/flask/app.py", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/flask/app.py", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/ubuntu/workspace/pset7.1/finance/helpers.py", line 34, in decorated_function
    return f(*args, **kwargs)
  ***File "/home/ubuntu/workspace/pset7.1/finance/application.py", line 66, in index
    total=usd(total1), id=session["user_id"], symbol=symbol)***
  File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/cs50/sql.py", line 178, in execute
    statement = str(statement.compile(compile_kwargs={"literal_binds": True}))
  File "<string>", line 1, in <lambda>

  File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/sqlalchemy/sql/elements.py", line 442, in compile
    return self._compiler(dialect, bind=bind, **kw)
  File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/sqlalchemy/sql/elements.py", line 448, in _compiler
    return dialect.statement_compiler(dialect, self, **kw)
  File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/sqlalchemy/sql/compiler.py", line 453, in __init__
    Compiled.__init__(self, dialect, statement, **kwargs)
  File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/sqlalchemy/sql/compiler.py", line 219, in __init__
    self.string = self.process(self.statement, **compile_kwargs)
  File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/sqlalchemy/sql/compiler.py", line 245, in process
    return obj._compiler_dispatch(self, **kwargs)
  File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/sqlalchemy/sql/visitors.py", line 81, in _compiler_dispatch
    return meth(self, **kw)
  File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/sqlalchemy/sql/compiler.py", line 775, in visit_textclause
    self.post_process_text(textclause.text))
  File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/sqlalchemy/sql/compiler.py", line 763, in do_bindparam
    return self.process(textclause._bindparams[name], **kw)
  File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/sqlalchemy/sql/compiler.py", line 245, in process
    return obj._compiler_dispatch(self, **kwargs)
  File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/sqlalchemy/sql/visitors.py", line 81, in _compiler_dispatch
    return meth(self, **kw)
  File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/sqlalchemy/sql/compiler.py", line 1244, in visit_bindparam
    bindparam, within_columns_clause=True, **kwargs)
  File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/sqlalchemy/sql/compiler.py", line 1277, in render_literal_bindparam
    return self.render_literal_value(value, bindparam.type)
  File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/sqlalchemy/sql/compiler.py", line 1292, in render_literal_value
    return processor(value)
  File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/sqlalchemy/sql/type_api.py", line 1126, in process
    return process_param(value, dialect)
  File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/cs50/sql.py", line 147, in process_literal_param
    return process(value)
  File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/cs50/sql.py", line 141, in process


    *raise RuntimeError("unsupported value")
RuntimeError: unsupported value*
1

Here you replace the string with a dict:

symbol = lookup(symbol)

here you use symbol:

    db.execute("UPDATE log SET price=:price, \
                total=:total WHERE id=:id AND symbol=:symbol", \
                price=usd(symbol["price"]), \
                total=usd(total1), id=session["user_id"], symbol=symbol)

Either use another variable name (which I would prefer), or use symbol=symbol["symbol"]) (which looks confusing).

You must log in to answer this question.

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