TypeError: a bytes-like object is required, not ‘str‘

移植python2的代码到python3环境时遇到套接字返回类型不一样的问题。
python中str和bytes是两种类型,一般从网路(如tcp/udp)或磁盘(如open函数返回的句柄)中读取的字节流都是bytes类型。
类型转换:
str→bytes:encode()
bytes→str:decode()

猜你喜欢

转载自blog.csdn.net/weixin_43749427/article/details/113511546