When Python raises an error, start with the final line of the traceback: it names the exception and usually gives a short explanation. Then inspect the source line identified just above it, along with the values and objects used there. The ten errors below are a practical selection for beginners—not a measured ranking of which errors happen most often.
Python distinguishes errors detected while parsing code from exceptions raised while running syntactically valid code. As the Python 3.11 tutorial puts it, “There are (at least) two distinguishable kinds of errors: syntax errors and exceptions.” Python’s Errors and Exceptions tutorial explains both.
How to read a Python traceback
- Read the last line first. It gives the exception type and often a message, such as
TypeError: ...orFileNotFoundError: .... - Find the relevant source frame. Move upward through the traceback to the line in your code where the exception was raised. A traceback can include calls through several functions; the visible failure may be downstream from the value or state that caused it.
- Inspect the expression’s inputs. Check the actual type, value, length, keys, or path involved—not just what you expected it to contain.
- Make the smallest correction that matches the program’s intent. Avoid hiding an error with a broad exception handler or inserting a default value without deciding what that default should mean.
A syntax error is caught as Python parses a file, before that invalid code can run. An exception occurs during execution. The arrow in a syntax-error message marks where the parser detected a problem, but the mistake can be just before the arrow, such as a missing colon.
Ten Python errors and their first fixes
1. SyntaxError
SyntaxError means Python could not parse the code’s form. Check the indicated line and the preceding token for a missing colon, unmatched parenthesis, quote, or other punctuation. For example, an if statement needs a colon:
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Repair Windows errors before they cause bigger problemsFix Now →#1 Best Overall
if score >= 60:
print("Pass")
If the reported location looks correct, inspect the line before it: an unclosed quote or bracket there can make the parser point later than the original mistake.
2. IndentationError and TabError
IndentationError is a kind of SyntaxError related to indentation. Python uses indentation to define blocks, so statements in the same block must line up. TabError indicates inconsistent use of tabs and spaces. Re-indent the affected block consistently, using one style throughout the file; do not try to fix it by adding spaces at random.
for name in names:
print(name)
save(name)
Both statements inside the loop are aligned. A statement intended to follow the loop belongs at a different indentation level.
3. NameError
NameError means Python could not find a local or global name used without qualification. Check spelling and capitalization, then confirm the name is assigned before the line that uses it and is available in that scope.
Recommended Free Tools
user_name = "Ada"
print(username) # NameError: the assigned name was user_name
Python treats user_name and username as different names. If a name exists in another function, check whether it should be passed into the current function rather than relying on an unrelated scope.
Rank #2
4. TypeError
TypeError signals that an operation or function received an inappropriate type. One common example is trying to add text and an integer:
age = 30
message = "Age: " + age
Choose a fix that preserves the intended meaning. If the goal is display, convert the integer to text or use an f-string:
message = f"Age: {age}"
If the operation is meant to be numeric, check why one input is text rather than converting blindly. Converting user input with int(), for example, can itself fail when the text is not a valid integer.
5. ValueError
ValueError means an operation received a value of an appropriate general type, but the value itself is unsuitable and no more specific exception describes the problem. For example, converting the string "thirty" to an integer cannot succeed. Inspect the actual input, then validate or normalize it before the operation. Do not confuse this with TypeError: that usually points to the kind of object being supplied, while ValueError points to its unacceptable value.
6. IndexError
IndexError means a sequence index is outside its valid range. For a list with len(items) elements, valid positive indexes run from 0 through len(items) - 1.
items = ["red", "blue"]
print(items[2]) # IndexError
Check the sequence’s length and how the index is calculated, especially at loop boundaries. If the sequence may be empty, handle that case before indexing rather than assuming element zero exists.
7. KeyError
KeyError usually means a mapping lookup requested a key that is not present. Inspect the mapping’s actual keys and check whether the requested key may be absent. If absence is expected, use a deliberate guard or a default-value pattern:
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Fix the driver behind crashes, sound loss and screen glitches3Clear out junk files and repair common Windows errorssettings = {"theme": "dark"}
theme = settings.get("theme", "light")
Use a default only when that fallback is correct for the program. If a missing key indicates malformed input or a bug, report or handle that condition instead of silently continuing with a misleading value.
8. AttributeError
AttributeError means an attribute reference or assignment failed. Check the object’s actual type and whether the attribute exists on that type. Also consider whether a variable unexpectedly contains None or a different kind of object than intended.
user = None
print(user.name) # AttributeError: None has no name attribute
Trace where the object came from and why it has that value. Adding a conditional is suitable only if the program has a defined way to handle a missing object; otherwise, fix the source of the unexpected value.
9. ModuleNotFoundError
ModuleNotFoundError is an ImportError subtype raised when Python cannot locate an imported module. Check the module name’s spelling, whether it is installed in the interpreter environment running your script, and whether that is the environment you intended to use. Installing a package in one environment does not establish that another interpreter can import it.
Check which Python interpreter launches the program and which environment has the dependency. The correct installation command depends on your setup; the key is to install the needed package for the interpreter that actually runs the code, not simply to repeat an install in an arbitrary terminal.
10. FileNotFoundError
FileNotFoundError means Python could not resolve the requested file at the path used. Check the spelling, the current working directory, and the file’s actual location. A relative path is interpreted in relation to the process’s working directory, which may differ from the directory containing your script.
from pathlib import Path
path = Path("data.txt")
print("Working directory:", Path.cwd())
print("Resolved path:", path.resolve())
Use the printed paths to see where Python is looking. Correct the path or working directory to match where the file really is; do not assume that moving or renaming a file is the right fix.
A repeatable debugging routine
- Classify the problem. A syntax or indentation error prevents parsing; an exception identifies a failure during execution.
- Read the exception’s exact wording. The type narrows the question: is the name missing, the type unsuitable, the value invalid, or the requested item absent?
- Inspect the values at the failing expression. Temporarily print or otherwise inspect a variable’s value and type. For a collection, check its length or keys; for a file, check the resolved path.
- Trace the value backward if necessary. If the named line only reveals the failure, follow the traceback and the data flow to find where the unexpected value originated.
- Correct the cause, then run the code again. A fix to one error can expose a separate problem further along. Treat each new traceback on its own evidence.
Handle exceptions narrowly
Use try only around the operation expected to fail, and catch the specific exception your program knows how to handle. If a file may be missing, for instance, catch FileNotFoundError around the file-opening operation—not around a large block of unrelated work. A broad handler can catch failures you did not intend to handle and make the real cause harder to find.
Free tools Windows power users keep installed
One-click scans. No signup required.
Best Value
try:
file = open("data.txt", encoding="utf-8")
except FileNotFoundError:
print("The data file was not found.")
else:
with file:
contents = file.read()
The else block runs only when the protected operation completes without the caught exception. If an exception is unexpected, let it propagate or re-raise it after recording useful context; do not make the program appear successful when it is not. The Python 3.11 tutorial on errors and exceptions recommends handling specific exceptions and allowing unexpected ones to propagate. Definitions and exception relationships are in the Python 3.11 built-in exceptions reference.
Or skip the browser setup
If you need a clean capture of a page while diagnosing a website or documenting a reproduction, ScreenshotNeo offers a screenshot API and MCP server. Its GET endpoint can return a screenshot or PDF; here is the Python request pattern:
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
See the ScreenshotNeo documentation for API details. Cookie banners, popups, and chat widgets are removed before capture; bot checks, blank pages, and failed loads are not billed. Its MCP server lets AI agents take screenshots. The Free plan includes 1,000 screenshots a month without a card, and paid plans start at $5 for 3,000. Sign up for 1,000 free screenshots a month, with no card required.
Frequently Asked Questions
Are these the ten most frequent Python errors?
No published frequency ranking is established here. They are a practical selection of errors beginners can diagnose from a traceback.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Which documentation version is linked?
The links point to the Python Software Foundation’s Python 3.11 tutorial and built-in exceptions reference.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

