-1

Hello im working on a Python project that makes my pentesting easier. I made the code in Visual Studio Code and pasted the code to my Kali Linux virtual machine. I got a error that says

TabError: inconsistent use of tabs and spaces in indentation

In Visual Studio Code, the code worked perfectly fine and i didn't get the error, but when i pasted the code into my Kali Linux i got that error. And if someone says to me, "Use the indetation converter in Visual Studio", i have already done that but it doesn't seem to work...

Here is the part of code, i'm not completely sure, if the community needs the whole code so i will just put the def function included code:

Problem is at "###" marks

def gobuster(target):
    if plat == "Windows" or plat == "windows":
        os.system("cls")
    if plat == "Linux" or plat == "linux":
        os.system('clear')
    print("Gobuster\n...")
    print('''        1# Basic Scan:
        2# Without progress monitoring ''')
    ids = int(input("Enter the ID of the scan:   "))
    if ids == 1:
        os.system("Touch %s_gobuster.txt" % target)

        ###
        buster = "gobuster dir -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -no-error -t 60 -o /home/kali/Desktop/ -u " + target
        os.system(buster)
        ###
MattDMo
  • 96,286
  • 20
  • 232
  • 224
HozeFN
  • 1
  • 4
  • is it the same directory on both systems? – Riceblades May 25 '22 at 17:26
  • 1
    You're mixing tabs and spaces on those lines. In VSCode, use the Convert Indentation to Spaces function so that you are consistently using spaces. This is the accepted community standard, defined in [PEP 8 -- The Style Guide for Python Code](https://www.python.org/dev/peps/pep-0008/). – MattDMo May 25 '22 at 17:28
  • @dwahwuiadhwaiudwuhwaiudhwa the code is only supposed to work on Kali Linux, for now atleast. But i tried replacing the `gobuster dir -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -no-error -t 60 -o /home/kali/Desktop/ -u ` with like "print hello" but still didn't work – HozeFN May 25 '22 at 17:31
  • 1
    Do you understand how indentation and spacing works in general? In Python? Are you able to comprehend what the error is telling you? Do you know how to use an IDE or text editor to convert spaces to tabs and vice versa? What exactly are you not clear on? – Random Davis May 25 '22 at 17:32
  • Hello, @MattDMo . Like i said, i tried doing that already, but... i only did it to the last 4-6 rows, or do you mean i should convert the entire code or the entire def function? – HozeFN May 25 '22 at 17:34
  • It should be the entire code. While you're at it, set your preferences so that code is only indented using spaces. I've found that using tabs anywhere is just asking for trouble down the line. – MattDMo May 25 '22 at 17:38
  • @RandomDavis Did you read the text? I said i know how to code and i have coded in vscode for 1 year, without this specific problem, but now that i took the code from VSCode~Windows to Kali Linux~Document it gives the error, and incase you say something about the "Document", the document becomes python script after i add .py to the end. – HozeFN May 25 '22 at 17:38
  • Unrelated, but on line 11, `Touch` should be `touch`. Linux is case-sensitive. – MattDMo May 25 '22 at 17:41
  • @gre_gor Well, I saw that one too but i trought the error has something to do with me changing os or something outside python, but i got it fixed by converting entire code to spaces – HozeFN May 25 '22 at 17:42
  • Thank You @MattDMo i changed the **entire** code to spaces and i got it to work. Ooh and big thanks for the reminder of the "Touch" one, i almost forgot case-sensitiveness. Actually i tried it with big letter and got no error but it didnt make the file, but with ur tip it did :) Is there any way of marking that you solved the issue? – HozeFN May 25 '22 at 17:47
  • @RandomDavis Hmm so its my fault that 3 code editors didn't care about the spacing on Windows but Linux does? And if i haven't faced the problem once in 1 year on Windows im suppose to just directly know that the same way doesnt work for Linux? Its a virtual machine dude, i barely use it. – HozeFN May 25 '22 at 17:58

0 Answers0