Common causes
- A line is accidentally indented when it should be at the top level
- Mixing tabs and spaces — one editor used tabs, another used spaces
- Copy-pasting code from a website or document that added extra leading spaces
- An extra level of indentation after a block that's already closed
How to fix it
- Check the indented line and remove extra leading spaces or tabs
- Use consistent indentation throughout — 4 spaces per level is the Python standard (PEP 8)
- Run your editor's 'convert tabs to spaces' feature to eliminate mixed whitespace
- In your editor, enable 'show whitespace' to make invisible characters visible
Example
File "app.py", line 3
x = 1
^
IndentationError: unexpected indentA line is indented inside the top-level scope where no block is open
Have a different error?
Paste any error message into the Error Translator to get an instant explanation.
