TypeError: 'NoneType' object is not subscriptable
You used [ ] on a value that is None — typically a function that returned nothing.
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
- 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]
How to diagnose
- Source — Where was the variable assigned?
- Return — Does that function always return a value?
🧠 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.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 2 Oct 2026