TCP客户端运行出错 TypeError: a bytes-like object is required, not ‘str’解决办法

今天爱分享给大家带来TCP客户端运行出错 TypeError: a bytes-like object is required, not ‘str’解决办法,希望能够帮助到大家。

问题截图:
TypeError: a bytes-like object is required, not ‘str’

解决思路
问题出在python3.5和Python2.7在套接字返回值解码上有区别:
python bytes和str两种类型可以通过函数encode()和decode()相互转换,
str→bytes:encode()方法。str通过encode()方法可以转换为bytes。
bytes→str:decode()方法。如果我们从网络或磁盘上读取了字节流,那么读到的数据就是bytes。要把bytes变为str,就需要用decode()方法。

解决方法

line.strip().split(“,”)

改为

line.decode().strip().split(“,”)

大功告成!

原文链接:https://blog.itblood.com/329.html,转载请注明出处。
0
女神的最佳交易3.8.5汉化版[PC+安卓/3.6G/更新]My Best Deal [v3.8.5] [欧美SLG/AI汉化/动态]
女神的最佳交易3.8.5汉化版[PC+安卓/3.6G/更新]My Best Deal [v3.8.5] [欧美SLG/AI汉化/动态]
9分钟前 有人购买 去瞅瞅看

站点公告

显示验证码
没有账号?注册  忘记密码?