0

I have the latest (I think) distribution code and I have exported the API key. Here is my code and it keeps returning 'None'. I can't figure out why I can't look up a stock quote. Do I need to change the helper.py function for lookup? Because I assumed that was already written fully.

@app.route("/quote", methods=["GET", "POST"])
@login_required
def quote():
    """Get stock quote."""
    if request.method == "GET":
        return render_template("quote.html")
    else:
        # lookup symbol that was submitted
        if not request.form.get("stock"):
            return apology("must provide stock symbol")
        else:
            symbol = request.form.get("stock")
            quote = lookup(symbol)
            if quote != None:
                return render_template("quoted.html", quote=quote)
            else:
                return apology("Cannot retrieve quote")

Here is the html

{% extends "layout.html" %}

{% block title %}
    Quote
{% endblock %}

{% block main %}
    <form action="/quote" method="post">
        <div class="form-group">
            <input autocomplete="off" autofocus class="form-control" name="stock" placeholder="Stock Symbol" type="text">
        </div>
        <button class="btn btn-primary" type="submit">Quote</button>
    </form>
{% endblock %}
1

Since the quote spec calls for an element named "symbol", and this if not request.form.get("stock"): is apparently working, it looks like the element is not named properly in the html.

FYI to change "I think" to "I know".

ls -al helpers.py 

(in the finance directory) should return

-rw------- 1 ubuntu ubuntu 1748 Apr  9 01:58 helpers.py

The cksum is 334135655.

Since the quote spec calls for an element named "symbol", and python get() doesn't return an error if the key is not found, strong likelyhood it's a typo.

5
  • -rw-r--r-- 1 ubuntu ubuntu 1748 Apr 9 01:45 helpers.py This is what it returned, but this doesn't mean anything to me. I don't know enough about programming to understand how this could affect my lookup function.
    – Lperino
    Sep 9 at 6:02
  • Sorry for the misdirect, I should have put the bottom line up front. Answer has been rearranged to highlight the suspected problem. Sep 9 at 11:35
  • Thanks for helping, I just can't see the problem still. Even if I change "stock" to "symbol" in both the .py and .html pages, it doesn't work. I still get my apology that it could not retrieve quote. Maybe I need to nuke it and start all over.
    – Lperino
    Sep 9 at 17:29
  • Just to be sure, you could download helpers.py from the spec again, since the time stamp on your file is earlier (01:45) than the time stamp on the download file (01:58). Also make sure the API_KEY is what you expect. Look in the flask log (in flask run terminal) to verify the API_KEY (token). The line will begin DEBUG: https://cloud.iexapis.com:443, Also have a look at the return value from that call (after the GET string). Here is a list of iex api error codes, FYI. Sep 9 at 18:42
  • You were right. I looked closely at anything that could have been a typo before nuking everything. Sure enough... the API key left off the last digit. I've been pulling my hair out for the past 3 days trying to figure that out. Thanks so much for your help!
    – Lperino
    Sep 9 at 18:43

You must log in to answer this question.

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