0

I am trying to make a web proxy that is multi threaded. I can do a single threaded one just fine but when I try to use multi-threading it throws this error every time.

Traceback (most recent call last):
  File "malwareProxy.py", line 25, in newClientInteraction
    request = clientSocket.recv(BUFFLEN)
TypeError: 'member_descriptor' object is not callable

I have these imports:

import sys
import thread
from socket import *

And the important bits of code:

def newClientInteraction(clientSocket, addr):
    try:
        port = 80

        request = clientSocket.recv(BUFFLEN)
....
serverListener = socket(AF_INET, SOCK_STREAM)
    serverListener.bind(("", serverPort))
    serverListener.listen(100)
    print("\nProxy Server listening on port {0}...".format(serverPort))

    # Start to listen for connections
    while True:
        (newsocket, addr) = serverListener.accept()
        print("Connection made from: {0}".format(newsocket.getpeername()))

        thread.start_new_thread(newClientInteraction, (socket, addr))

Please help. I am pretty new to python and have no idea why I am getting this error. I have looked at some other posts about this error and the answers seem to have to do with the programmer using multiple files and imports I am just using the one file. Thank you.

J Blaz
  • 783
  • 1
  • 6
  • 26
  • 1
    When you start the thread, you seem to pass **socket** while you had created a __(newsocket, addr)__ pair two lines above. Try passing **newsocket** in the __thread.start_new_thread__ call. – sal Jan 24 '17 at 23:07
  • I am really stupid! THank you. – J Blaz Jan 24 '17 at 23:12
  • 1
    No you're not. It's an unfortunate spelling mistake. I added an answer: please accept it if right. :) – sal Jan 24 '17 at 23:18

1 Answers1

1

The error is due to an unfortunate typo in passing the parameters when starting the new thread. Unfortunate because it matches a name in the socket library, thus the error generated is harder to debug.

The error message can be reproduced by trying to call:

 import socket
 socket.socket.recv(BUFFLEN)

which is what that typo is producing. Thankfully, it's easy to fix, by changing this line:

thread.start_new_thread(newClientInteraction, (socket, addr))

to read instead

thread.start_new_thread(newClientInteraction, (newsocket, addr))
sal
  • 3,515
  • 1
  • 10
  • 21
  • 2
    Can you explain what `member_descriptor` is? I am also having a similar issue but with `cur_time = cur_time + timedelta.seconds(1)` <-- I don't think this has anything to do with sockets... – Hendy Irawan Jan 15 '18 at 12:33
  • 2
    Update: It seems I needed to use `cur_time = cur_time + timedelta(seconds=1)`. However I'm still confused why there is `member_descriptor` there... – Hendy Irawan Jan 15 '18 at 12:34