IndentationError: unexpected indent / expected an indented block
Python’s block structure is broken — inconsistent indentation or mixed tabs and spaces.
Seen on:
Python
Meaning
Indentation is syntax in Python. Every block after : must be indented consistently, and mixing tabs and spaces (TabError) is not allowed.
Common causes
- Mixed tabs and spaces
- Empty block after
if/def/for(usepass) - Copy-pasted code with different indentation
- Stray indentation on a top-level line
⚡ Quick fix
- Configure the editor to insert 4 spaces
- Convert tabs to spaces for the file
- Add
passto empty blocks
Detailed fix by platform
Python
python -m tabnanny file.pyreports ambiguous indentation.
How to diagnose
- Line — Reported line and block above
- Whitespace — Tabs vs spaces?
🧠 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