I have been trouble shooting this for a while now. I have the Quote page working and I verified the stock symbol is being sent over correctly to the lookup function. I have done the export API_Key command and verified the key is being sent correctly. I even changed the token to see if the return code changed, and it did. So not the API token. I researched the 402 code and it has 3 possible reasons.

  1. Over limit
  2. Free tier not allowed
  3. Tier not allowed

I did verify that my Free account still shows the credits I have to use.

Did I signup for the API wrong or did they change the free account privileges? Are others having this issue? I seem to be locked out of moving forward when the provided API wont work as it needs to. I shouldn't have to pay for the account to complete this course. I even opened a 2nd trial account with different email and dropdown choices in case it was categorizing me. Nothing changed.

Any help would be great...

Terminal Log

DEBUG: Starting new HTTPS connection (1): cloud.iexapis.com:443
DEBUG: https://cloud.iexapis.com:443 "GET /stable/stock/NFLX/quote?token=pk_*********9bbe HTTP/1.1" 402 None

Provided code from CS50

def lookup(symbol):
    """Look up quote for symbol."""

    # Contact API
        api_key = os.environ.get("API_KEY")

        url = f"https://cloud.iexapis.com/stable/stock/{urllib.parse.quote_plus(symbol)}/quote?token={api_key}"
        response = requests.get(url)
    except requests.RequestException:
        return None

Error code list from https://www.iexcloud.io/docs/api/#error-codes

402 Over Limit              You have exceeded your allotted credit quota (and pay-as-you-go is not enabled on legacy plans).
402 Free Tier Not Allowed   The requested endpoint is not available to free accounts.
402 Tier Not Allowed        The requested data is not available to your current tier.

1 Answer 1


It appears that iex has changed their offerings and the new 'free trial' keys do not give access to the stocks via our lookup function.

We are investigating a new method, but in the meantime, this workaround should help.

Replace your lookup function in helpers.py with this. It gives you 4 symbols you can use in your testing.

# Hard coded stock for testing CS50 Finance without using the API 
# Useful for testing scenarios of pricing/formatting with certainty 

def lookup(symbol):

    if symbol == "AAAA":
        return {"name": "Test A", "price": 28.00, "symbol": "AAAA"}
    if symbol == "BBBB":
        return {"name": "Test B", "price": 3.27, "symbol": "BBBB"}
    if symbol == "CCCC":
        return {"name": "Test C", "price": 35.30, "symbol": "CCCC"}
    if symbol == "DDDD":
        return {"name": "Test D", "price": 0.28, "symbol": "DDDD"}
    return None

Apologies for any inconvenience.

  • Thanks. I will be working on this later tonight. When it comes time to submit to check50 for credit, will this go through?
    – Eric Engel
    Dec 6, 2022 at 3:57
  • 1
    Yes, check50 uses its own lookup function anyway.
    – curiouskiwi
    Dec 6, 2022 at 4:08
  • Thanks for this. I was looking for a solution to the same problem, and was going to assemble something like this if I hadn't found anything better. I suppose this saves me even having to add it. (If helpers isn't used I may need to move some of my own helpers out to app.py...)
    – Dave
    Feb 13, 2023 at 23:10

You must log in to answer this question.

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