TypeError: 'NoneType' object is not subscriptable
You used [ ] on a value that is None — typically a function that returned nothing.
'NoneType' object is not subscriptableNoneType object is not subscriptable'NoneType' object is not iterable 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
- Print the variable right before the failing line
- Use
sorted(items)instead ofitems.sort()when you need the result - Check for None before indexing
Detailed fix by platform
Python
- 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
def load_user(uid):
user = db.get(uid)
# ❌ missing "return user"
user = load_user(7)
print(user["name"]) # TypeError: 'NoneType' object is not subscriptableIn-place methods return None
items = [3, 1, 2]
items = items.sort() # ❌ items is now None
items = sorted(items) # ✅ returns a new listHow to diagnose
- Variable — Which variable is None at the failing line?
- Origin — Trace back to where it was assigned
- Returns — Does that function return on every path?
- 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:
Similar errors
Most viewed in Python
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 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.
Report a correction or suggest an improvement
Last updated 15 Oct 2026