TypeError: recv_thread() argument after * must be an iterable, not socket

错误

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.

相关推荐
知星小度S2 小时前
系统核心解析:深入操作系统内部机制——进程管理与控制指南(一)【进程/PCB】
linux·运维·服务器·进程
xchenhao3 小时前
SciKit-Learn 全面分析分类任务 breast_cancer 数据集
python·机器学习·分类·数据集·scikit-learn·svm
编码浪子5 小时前
趣味学RUST基础篇(异步)
服务器·rust·负载均衡
独行soc6 小时前
2025年渗透测试面试题总结-66(题目+回答)
java·网络·python·安全·web安全·adb·渗透测试
码农101号6 小时前
运维安全05 - iptables规则保存与恢复
运维·网络·安全
Empty_7776 小时前
SELinux安全上下文
linux·服务器·安全
bug攻城狮7 小时前
解决Ubuntu中apt-get -y安装时弹出交互提示的问题
linux·运维·ubuntu
夜阑珊夭夭8 小时前
linux自定义网卡名字
linux·运维
佛天华8 小时前
centos 时间校准
linux·运维·centos
Y学院8 小时前
Python 数据分析:从新手到高手的“摸鱼”指南
python·数据分析