Python’s TypeError is basically the interpreter telling you: “I know what this is, but I can’t do that with it.” It usually happens because you’re trying to treat an object like something it isn’t—like trying to use a dictionary key on a variable that’s actually None.

The “Cheat Sheet” for Quick Fixes

  • ‘NoneType’ object is not subscriptable: You tried data['key'] but data is None. Check why your function didn’t return a dictionary.
  • can only concatenate str (not “int”) to str: You’re adding a number to a string with +. Use an f-string instead: f"Total: {value}".
  • ‘int’ object is not iterable: You tried to loop (for x in ...) over a number. You probably forgot range().
  • ‘list’ object is not callable: You named a variable list = [1, 2] and then tried to use list(). Change your variable name.

‘NoneType’ object is not subscriptable

This is the big one. “Subscriptable” just means “can I use [] on this?”.

It usually happens when you chain a function that returns nothing (None) or when a database/API lookup fails.

# ❌ The Crash
user = get_user_from_db(id=999) # Returns None if not found
print(user['name']) # 💥 TypeError: 'NoneType' object is not subscriptable

The Fix: Always check if the object exists before digging into it.

user = get_user_from_db(id=999)
if user:
    print(user['name'])

Mixing Strings and Ints

If you come from JavaScript, you’re used to the language “fixing” types for you. Python won’t do that.

# ❌ The Crash
items = 3
print("You have " + items + " messages") # 💥 TypeError: can only concatenate str (not "int") to str

The Fix: Stop using + for strings. Use f-strings—they handle the conversion and are much faster.

print(f"You have {items} messages")

‘int’ object is not iterable

This usually happens when you’re trying to loop over a count rather than a range or a list.

# ❌ The Crash
attempts = 3
for i in attempts: # 💥 TypeError: 'int' object is not iterable
    print(i)

The Fix: Use range() if you want to loop a specific number of times.

for i in range(attempts):
    print(i)

Don’t Shadow Built-ins

A very common mistake for beginners is naming a variable after a Python built-in like list, dict, or type.

# ❌ The Crash
list = [10, 20] # You just "deleted" the list() function in this file
# ... later ...
other_data = list("abc") # 💥 TypeError: 'list' object is not callable

The Fix: Pick better names. Use items, user_list, or data_dict instead.

How to debug these faster

When you see a TypeError in your logs:

  1. Look at the Traceback: The last line tells you the clashing types (e.g., int and str).
  2. Verify with type(): If you aren’t sure what a variable is, print(type(my_var)) right before it crashes. You’ll often find a None where you expected data.
  3. Use Type Hints: If you’re using VS Code or PyCharm, add type hints like def process(data: list):. The IDE will highlight mistakes in red before you even run the code.

Tired of digging through messy Python tracebacks? Paste your error into Debugly to get a clean, formatted view of what actually went wrong.