Search code examples
pythonindentation

How to resolve "IndentationError: unexpected indent"


I'm running Kali Linux and need to pull off a load of commands, but I'm making a script to really speed that up for me. Here is the .py file:

import os

if raw_input("Begin fake Access Point? (y/n): ")=="y":
 os.system(airmon-ng)

interface = input("Enter your Interface name: ")
 os.system(airmon-ng "interface" start)

I'm getting this error when trying to run it:

  File "WNS.py", line 7
    os.system(airmon-ng "interface" start)
    ^
IndentationError: unexpected indent

Tried to remove the whitespace in the beginning but then I just get this error:

IndentationError: expected an indented block


Solution

  • Indendation is very important in Python. It is used by the interpreter to know how to delimit blocks of instructions.The parameters to the os.system() call don't look good either. Anyway this is how it's supposed to look like

    import os
    
    if raw_input("Begin fake Access Point? (y/n): ")=="y":
        os.system("airmon-ng")
    
    interface = input("Enter your Interface name: ")
    os.system("airmon-ng "+interface+" start")