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.

相关推荐
witAI23 分钟前
**AI仿真人剧制作软件2025推荐,解锁沉浸式数字内容创作
人工智能·python
cyber_两只龙宝1 小时前
Nginx--企业高性能web服务器高级配置详解
linux·运维·nginx·云原生
Codefengfeng2 小时前
Python Base环境中加包的方法
开发语言·python
清水白石0082 小时前
《Python 编程全景解析:从核心精要到测试替身(Test Doubles)五大武器的实战淬炼》
开发语言·python
如若1233 小时前
AutoDL云服务器 NVIDIA 570驱动 EGL渲染修复全记录
运维·服务器·python
i建模3 小时前
Omarchy设置防火墙
linux·运维
甲枫叶3 小时前
【claude】Claude Code正式引入Git Worktree原生支持:Agent全面实现并行独立工作
java·人工智能·git·python·ai编程
晚秋大魔王3 小时前
泰拉瑞亚手机版服务器部署
运维·服务器·泰拉瑞亚
敲代码的哈吉蜂3 小时前
高可用集群Keepalived
运维·服务器·网络·数据库
清水白石0083 小时前
《Python 编程全景解析:从核心精要到 Hypothesis 属性基测试的边界探索》
开发语言·python