I'm not sure if I understand this correctly. I've written the following bit of simple code:

for portfolio in portfolios:

    symbol = portfolio["symbol"]
    look = lookup(symbol)
    price = float(look["price"])

However, sometimes, usually, when reloading the page it gives me the error that look"["price"] -- 'NoneType' object is not subscriptable.

I assume it returns the lookup, but not the price elements.

1 Answer 1


It would do so if it cannot lookup the symbol. In that case, lookup returns None, a special value of type NoneType indicating absense of something, like proper data.

Since you are looping a list portfolios, I assume those are symbols of stocks already bought, so they should exist.

That seems a frequent problem currently, the API sometimes not returning the expected data, implementing some kind of cache might help (to reduce the number of requests, or re-use an old response if the request fails). I'm not sure the average student is expected to write such thing.

As far as I know, the check50 and submit50 checkers do not rely on those external services, and inject their own lookup (to test your code in certain situations, like whether you render a money value with trailing zeroes like $42.00 correctly). So if you are sure your code is right, even though it sometimes fails for this None response, you might still be able to submit.

  • 1
    (just FYI ... today we updated the finance spec and distro code to use a new, more reliable, API)
    – curiouskiwi
    Commented Jul 31, 2018 at 2:17
  • That's great, thanks!
    – Blauelf
    Commented Jul 31, 2018 at 4:20

You must log in to answer this question.

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