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:
JavaScript
x
4
1
File "C:Python27libthreading.py", line 754, in run
2
self.__target(*self.__args, **self.__kwargs)
3
TypeError: thre() takes no arguments (1 given)
4
The code here:
JavaScript
1
65
65
1
import socket
2
import sys
3
import time
4
import Queue
5
import colorama
6
import threading
7
from Queue import Queue
8
from threading import Thread
9
from colorama import Fore, Back, Style
10
colorama.init(autoreset=True)
11
12
13
print_lock = threading.Lock()
14
q = Queue()
15
num_threads = '10'
16
17
def sshcan(host):
18
19
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
20
21
try:
22
rez = s.connect_ex((host, port))
23
if rez == 0:
24
print (Fore.GREEN + Style.DIM + 'PORT {}: Open on', +host)
25
s.close()
26
time.sleep(0.1)
27
28
except sockect.error:
29
print (Fore.RED + Style.DIM + 'Couldn't connect to server')
30
sys.exit()
31
32
except KeyboardInterrupt:
33
print ('Stoping...')
34
sys.exit()
35
pass
36
37
def thre():
38
while True:
39
host = q.get()
40
sshcan(host)
41
q.task_done()
42
43
def main():
44
45
try:
46
host = open(raw_input('33[91m[33[92m+33[91m]33[92m File Path: 33[97m'),'r').read().splitlines()
47
48
port = raw_input('33[91m[33[92m+33[91m]33[92m Port: 33[97m')
49
50
for i in range(int(num_threads)):
51
thread = threading.Thread(target=thre,args=(i,))
52
thread.daemon = True
53
thread.start()
54
55
56
for host in range(5):
57
q.put(host)
58
59
pass
60
61
if __name__ == "__main__":
62
main()
63
64
q.join()
65
Advertisement
Answer
JavaScript
1
2
1
> def thre():
2
JavaScript
1
2
1
> Thread(target=thre, args=(i,))
2
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.