Skip to content
Advertisement

TypeError: thre() takes no arguments (1 given)

im new to learning python and was trying code port scan script using Queue and Threading python 2.7 it keep giving me this error. multiple error to be precise here is the last line of the erorr. meanwhile all the error have the “TypeError: thre() takes no arguments (1 given)”.

The error here:

File "C:Python27libthreading.py", line 754, in run
self.__target(*self.__args, **self.__kwargs)
TypeError: thre() takes no arguments (1 given)

The code here:

import socket
import sys
import time
import Queue
import colorama
import threading
from Queue import Queue
from threading import Thread
from colorama import Fore, Back, Style
colorama.init(autoreset=True)


print_lock = threading.Lock()
q = Queue()
num_threads = '10'

def sshcan(host):

    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

    try:
      rez = s.connect_ex((host, port))
       if rez == 0:
         print (Fore.GREEN + Style.DIM + 'PORT {}: Open on', +host)
      s.close()
      time.sleep(0.1)

    except sockect.error:
    print (Fore.RED + Style.DIM + 'Couldn't connect to server')
    sys.exit()
    
    except KeyboardInterrupt:
    print ('Stoping...')
    sys.exit()
    pass

 def thre():
     while True:
       host = q.get()
       sshcan(host)
       q.task_done()
    
def main():

    try:
       host = open(raw_input('33[91m[33[92m+33[91m]33[92m File Path: 33[97m'),'r').read().splitlines()

       port = raw_input('33[91m[33[92m+33[91m]33[92m Port: 33[97m')

       for i in range(int(num_threads)):
          thread = threading.Thread(target=thre,args=(i,))
          thread.daemon = True
          thread.start()
    
    
       for host in range(5):
           q.put(host)
    
           pass
    
    if __name__ == "__main__":
    main()

    q.join()

Advertisement

Answer

>  def thre():
>     ...Thread(target=thre, args=(i,))

The diagnostic is pretty clear.

You defined the function to take no args. And then you essentially called thre(i), offering a single arg. Definition differs from the call.

Make them match.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement