移植python2的代码到python3环境时遇到套接字返回类型不一样的问题。
python中str和bytes是两种类型,一般从网路(如tcp/udp)或磁盘(如open函数返回的句柄)中读取的字节流都是bytes类型。
类型转换:
str→bytes:encode()
bytes→str:decode()
TypeError: a bytes-like object is required, not ‘str‘
最新推荐文章于 2023-12-14 09:19:16 发布
移植python2的代码到python3环境时遇到套接字返回类型不一样的问题。
python中str和bytes是两种类型,一般从网路(如tcp/udp)或磁盘(如open函数返回的句柄)中读取的字节流都是bytes类型。
类型转换:
str→bytes:encode()
bytes→str:decode()