TypeError: 'NoneType' object is not subscriptable
TL;DRYour code tried to read a specific item from a list, dictionary or similar structure, but the thing it was looking at was empty (None) instead of actual data.
Most likely cause: A function returned None when the code expected a list or dictionary
Try first: Find the exact line causing the error
Likely causes
- A function returned None when the code expected a list or dictionarymost likely
- A variable was never assigned a value before being used with brackets like [0] or ['key']possible
- An earlier operation that should have created the data structure failed silentlyless likely
How to fix it
Safest first: SafeChanges settingsDangerous
Find the exact line causing the errorSafe
Look at the traceback and note the line number and variable name that is being subscripted.
Trace where that variable comes fromSafe
Check the function or line that assigned the variable and add a check to see if it is None before using it.
If that didn't fix it
Add a temporary print statement right before the error line to show the variable's value and type.
When to see a technician
If the error occurs inside a large or unfamiliar codebase, ask the original developer or a programmer familiar with the project for help.
Quick answers
- What does TypeError: 'NoneType' object is not subscriptable mean?
- Your code tried to read a specific item from a list, dictionary or similar structure, but the thing it was looking at was empty (None) instead of actual data.
- What causes TypeError: 'NoneType' object is not subscriptable?
- A function returned None when the code expected a list or dictionary. (most likely) A variable was never assigned a value before being used with brackets like [0] or ['key']. (possible) An earlier operation that should have created the data structure failed silently. (less likely)
- How do I fix TypeError: 'NoneType' object is not subscriptable?
- Try these in order, safest first: 1. Find the exact line causing the error. 2. Trace where that variable comes from.
- What if that didn't fix it?
- Add a temporary print statement right before the error line to show the variable's value and type.
- When should I see a technician?
- If the error occurs inside a large or unfamiliar codebase, ask the original developer or a programmer familiar with the project for help.
Related errors
codeTypeError: can only concatenate str (not "int") to strcodeTypeError: Failed to fetchcodeUncaught TypeError: Cannot read properties of null (reading 'addEventListener')codeTypeError: Cannot read properties of undefined (reading 'map')codeERROR: Could not find a version that satisfies the requirement (from versions: none)codeerror: Your local changes to the following files would be overwritten by merge: Please commit your changes or stash them