Common causes
- A function returned None instead of an object — common when a condition is met on no code path
- A database query or file parser found no results and returned None
- An in-place method (like dict.update() returning None) was stored and then accessed
- Optional chaining missing — accessing a.b.c when a.b can be None
How to fix it
- Check what the function returns before calling methods on it: print(result)
- Add a guard clause: if result is not None: result.do_something()
- Ensure the function has a return statement on every code path
- Use a default: result = get_user() or User.default()
Example
Traceback (most recent call last):
File "app.py", line 6, in <module>
print(user.name)
AttributeError: 'NoneType' object has no attribute 'name'Calling get_user() which returns None when no user is found, then accessing .name
Have a different error?
Paste any error message into the Error Translator to get an instant explanation.
