TypeError: NoneType Python Origin: Application & API Last updated 15 Oct 2026

TypeError: 'NoneType' object is not subscriptable

You used [ ] on a value that is None — typically a function that returned nothing.

Exact message you may see 'NoneType' object is not subscriptableNoneType object is not subscriptable'NoneType' object is not iterable
Seen on: Python

Meaning

Something you expected to be a list/dict is None. Classic causes: a function without return, in-place methods like list.sort() that return None, or a lookup that found nothing.

Common causes

  • Function missing return
  • Assigning result of in-place methods: x = items.sort()
  • re.match() returned None (no match)
  • DB/API lookup returned None

⚡ Quick fix

  1. Print the variable right before the failing line
  2. Use sorted(items) instead of items.sort() when you need the result
  3. Check for None before indexing

Detailed fix by platform

Python

  1. Regex match guard:
    python
    m = re.match(r"(\d+)", text)
    if m is None:
        raise ValueError(f"no number in {text!r}")
    number = m[1]

Code examples

Function that forgets to return

python
def load_user(uid):
    user = db.get(uid)
    # ❌ missing "return user"

user = load_user(7)
print(user["name"])     # TypeError: 'NoneType' object is not subscriptable

In-place methods return None

python
items = [3, 1, 2]
items = items.sort()    # ❌ items is now None
items = sorted(items)   # ✅ returns a new list

How to diagnose

  1. Variable — Which variable is None at the failing line?
  2. Origin — Trace back to where it was assigned
  3. Returns — Does that function return on every path?
  4. Lookups — Can the lookup legitimately find nothing? Handle it

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

AttributeError — AttributeError: 'X' object has no attribute 'y' (Python)AttributeErrorDivision by zero — SQL Error: division by zero / Divide by zero error encountered (SQL)Division by zeroKeyError — KeyError: 'x' (Python)KeyErrorNullPointerException — java.lang.NullPointerException (Java)NullPointerExceptionTypeError — TypeError: Cannot read properties of undefined (reading 'x') (JavaScript)TypeErrorTypeError const — TypeError: Assignment to constant variable. (JavaScript)TypeError constTypeError set undefined — TypeError: Cannot set properties of undefined (setting 'x') (JavaScript)TypeError set undefin…ZeroDivisionError — ZeroDivisionError: division by zero (Python)ZeroDivisionErrorTypeError…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.