<>Python Socket

TypeError: an integer is required (got type str)
Traceback (most recent call last): File "F:\py\demo.py", line 13, in <module> s
.connect((host,port)) TypeError: an integer is required (got type str)
可以看到Python提示连接时出错,出错的内容是an integer is required (got type str)

然后我看了下我的代码
host=sys.argv[1] port=sys.argv[2] #问题出在这行代码上 s=socket.socket(socket.AF_INET,
socket.SOCK_STREAM) s.connect((host,port))
<>只需要将Port(端口)传递的参数该为int类型就行,改完之后代码是这样的。
host=sys.argv[1] port=int(sys.argv[2]) #问题出在这行代码上 s=socket.socket(socket.
AF_INET,socket.SOCK_STREAM) s.connect((host,port))
问题解决。

技术
下载桌面版
GitHub
百度网盘(提取码:draw)
Gitee
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:ixiaoyang8@qq.com
QQ群:766591547
关注微信