错误
TypeError: recv_thread() argument after * must be an iterable, not socket的问题。
原因
这个错误是由于在创建一个线程时,将socket对象作为args参数传递给了recv_thread函数,而args参数需要一个可迭代的对象,比如元组或列表。
解决办法
可以通过在socket对象后面加一个逗号,将其转换为一个元组,来解决这个问题。代码是这样的:
def recv_thread(sock):
while True:
data = sock.recv(1024).decode()
thread = threading.Thread(target=recv_thread, args=(s))
可以改为:
def recv_thread(sock):
while True:
data = sock.recv(1024).decode()
thread = threading.Thread(target=recv_thread, args=(s,))
这样就可以避免TypeError: recv_thread() argument after * must be an iterable, not socket的错误了。
(1) Python Threading module Error argument after * must be an iterable, not int. multithreading - Python Threading module Error argument after * must be an iterable, not int - Stack Overflow.
(2) TypeError: send() argument after * must be an iterable, not socket in .... [Solved]TypeError: send() argument after * must be an iterable, not socket in Python.
(3) Python threading error - must be an iterable, not int. multithreading - Python threading error - must be an iterable, not int - Stack Overflow.
(4) python - TypeError: add() argument after * must be an iterable, not .... python - TypeError: add() argument after * must be an iterable, not Settings - Stack Overflow.