I have Finance barely ready but like most codes, it has a buggy near the finish line. I have a problem with lookup. Always return None. I check it.

and Terminal shows this error: TypeError: quote_from_bytes() expected bytes

Here's my python code where the bug is:

if request.method == "POST":
        """Sell shares of stock"""
        symbol = request.form.get("symbol")
        shares_sell = request.form.get("shares_sell")
        symbol_sell = lookup(symbol)

and here's my html code: Where I think the problem is.

<form action="/sell" method="post">
    <div class="form-group">
        <select class="form-control" style="text-transform: uppercase">
            <option disabled="" selected="" name="symbol">Symbol</option>
            {% for row in portfolio %}
            <option style="text-transform: uppercase; text-align: center" name="symbol">{{ row['symbol'] }}</option>
            {% endfor %}
        <input autocomplete="off" class="form-control" min="0" name="shares_sell" placeholder="Shares" type="number">
    <button class="btn btn-primary" type="submit">Sell</button>

I think that the problem is that I can't take the information about "symbol" at the HTML and take it as "symbol" to application.py. would it be because of the select button instead of the input?

thank you for the time! Regards, Santiago Correa


symbol is not submitted with the form because the name attribute needs to be defined on the select element. name is not a valid attribute for <option> elements, and the HTML will give errors if validated with Nu Html

From MDN doc on select:

a name attribute to represent the name of the associated data point submitted to the server

That is the cause of symbol always being None, but does not pinpoint the actual cause of the TypeError.

You must log in to answer this question.

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