成功解决AttributeError: 'str' object has no attribute 'decode'

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_41185868/article/details/82079079

解决问题

AttributeError: 'str' object has no attribute 'decode'

解决思路

python3.5和Python2.7在套接字返回值解码上的区别 
python在bytes和str两种类型转换,所需要的函数依次是encode(),decode()

解决方法

str通过encode()方法可以编码为指定的bytes
反过来,当从网络或磁盘上读取了字节流,那么读到的数据就是bytes。要把bytes变为str,就需要用decode()方法

猜你喜欢

转载自blog.csdn.net/qq_41185868/article/details/82079079