ProjectStack
python

TypeError: 'NoneType' object is not iterable

You're trying to iterate (loop over) a value that is None. A function you expected to return a list or other iterable returned None instead.

Common causes

  • A function that was supposed to return a list returned None (missing return statement)
  • An in-place method like list.sort() or list.reverse() was used in a for loop
  • A query or lookup returned None when nothing was found instead of an empty list
  • Chaining operations on a None value: for item in get_items().filter()

How to fix it

  1. Check the function that should return a list and verify it has a return statement
  2. Use an empty list as a fallback: for item in (get_items() or []):
  3. Separate the call from the iteration to inspect the value: items = get_items(); print(items)
  4. If using in-place list methods, call them separately then iterate the original list

Example

Traceback (most recent call last): File "app.py", line 5, in <module> for item in get_results(): TypeError: 'NoneType' object is not iterable

Iterating the return value of get_results() which returns None instead of a list

Have a different error?

Paste any error message into the Error Translator to get an instant explanation.