ProjectStack
python

AttributeError: 'NoneType' object has no attribute

You're trying to access a property or call a method on a value that is None. This almost always means a function or lookup returned None when you expected an object.

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

  1. Check what the function returns before calling methods on it: print(result)
  2. Add a guard clause: if result is not None: result.do_something()
  3. Ensure the function has a return statement on every code path
  4. 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.