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
- Check the function that should return a list and verify it has a return statement
- Use an empty list as a fallback: for item in (get_items() or []):
- Separate the call from the iteration to inspect the value: items = get_items(); print(items)
- 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 iterableIterating 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.
