Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IndentationError: unindent does not match any outer indentation level in msfrpc_smb.py #1

Open
Mazuco opened this issue Dec 13, 2016 · 4 comments

Comments

@Mazuco
Copy link

Mazuco commented Dec 13, 2016

When I type python msfrpc_smb.py -p batman -t 192.168.1.135 it return me a error below

File "msfrpc_smb.py", line 95 with open(ipfile) as f: ^ IndentationError: unindent does not match any outer indentation level

How to fix it?

@bbishop423
Copy link

bbishop423 commented Dec 19, 2016

I was able to recreate the problem locally on my machine. Seems like inconsistent use of tabs vs. spaces in the code. You can fix that yourself by going through the script and replacing each tab with 4 spaces. Python PEP-8 (https://www.python.org/dev/peps/pep-0008/) states that it is strongly recommended to use 4 spaces for each indentation level. If you don't want to go through manually and change each of the tabs in the file to 4 spaces you could write a python script to do that for you and run it over each file you need to clean up.

Example python script to remove indentation inconsistencies:

lines = []
with open('msfrpc_smb.py', 'r') as f:
    for line in f:
        line = line.replace('\t', '    ')
        lines.append(line)

with open('msfrpc_smb.py', 'w') as f:
    f.writelines(lines)

@aburumman
Copy link

very helpful

@gilgtc
Copy link

gilgtc commented Mar 27, 2018

python script that can be customized for filename and number of spaces and called from terminal. It also creates a backup of the file before operating on it. Based on @bbishop423:

# Fixes python files that contain mixed spaces and tabs.
# Typical error message: "IndentationError: unindent does not match any outer indentation level"
# Example usage:
#                 python fix_tabs.py -f clustering.py -s 2

import argparse
import shutil

if __name__ == '__main__':
  parser = argparse.ArgumentParser()
  parser.add_argument('-f', '--file', type = str, help='Specify filename.')
  parser.add_argument('-s', '--spaces', type = int, default = 4,
        help='Specify number of spaces. Default: %(default)s')
  args = parser.parse_args()
  
  shutil.copyfile(args.file, args.file + '.bkp')  

  lines = []

  with open(args.file, 'r') as f:
    for line in f:
      line = line.replace('\t', ' '*args.spaces)
      lines.append(line)

  with open(args.file, 'w') as f:
    f.writelines(lines)

@flutterq
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants