成功解决TypeError: a bytes-like object is required, not 'str'
成功解决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(",")
大功告成!
成功解决TypeError: a bytes-like object is required, not 'str'相关推荐
- 成功解决TypeError: ‘tuple‘ object is not callable
成功解决TypeError: 'tuple' object is not callable 目录 解决问题 解决思路 解决方法 解决问题 TypeError: 'tuple' object is no ...
- 成功解决TypeError: ‘str‘ object is not callable
成功解决TypeError: 'str' object is not callable 目录 解决问题 解决思路 解决方法 解决问题 TypeError: 'st
- 成功解决TypeError: object of type ‘int‘ has no len()
成功解决TypeError: object of type 'int' has no len() 目录 解决问题 解决思路 解决方法 解决问题 TypeError: object of type 'i ...
- 成功解决TypeError int object is not iterable
成功解决TypeError: 'int' object is not iterable 目录 解决问题 解决思路 解决方法 解决问题 TypeError: 'int' object is not it ...
- 成功解决TypeError: 'float' object cannot be interpreted as an integer
成功解决TypeError: 'float' object cannot be interpreted as an integer 目录 解决问题 解决思路 解决方法 解决问题 TypeError: ...
- 成功解决TypeError: ‘float’ object cannot be interpreted as an index
成功解决TypeError: 'float' object cannot be interpreted as an index 目录 解决问题 解决思路 解决方法 解决问题 TypeError: 'f ...
- 成功解决TypeError: sequence item 0: expected str instance, bytes found
成功解决TypeError: sequence item 0: expected str instance, bytes found 目录 解决问题 解决思路 解决方法 解决问题 TypeError: ...
- 成功解决TypeError: a bytes-like object is required, not ‘str‘
出现问题: 在文件写操作时出现TypeError: a bytes-like object is required, not 'str' 意思是函数write需要的参数类型是字节对象不是字符串 解决办 ...
- 成功解决TypeError: data type ‘category‘ not understood
成功解决TypeError: data type 'category' not understood 目录 解决问题 解决思路 解决方法 解决问题 TypeError: data type 'cate ...
最新文章
- source insight3.5显示中文_Doxygen 中文文档
- 【Tensorflow】ValueError: Only call `sigmoid_cross_entropy_with_logits` with named arguments
- 使用嵌套循环,打印 5 行 5 列的直角三角形
- CCD的基本的基本知识介绍(转载)
- Git和Github详细入门教程
- 华为交换机开启ftp服务,上传和下载文件,get和put操作实例
- 基于web的电影院订票系统(毕设系统,到手可用)
- 曼切斯特编码波特率和比特率的关系
- 机械工业设计中常见三维软件大盘点
- 浏览器提示网站链接不安全,证书过期了
- 笔试题:输入0123456789对应输出“一二三四五六七八九”
- 没有装php可以用phpmyadmin,phpMyAdmin 安装及问题总结
- linux ubuntu硬盘数据丢失【硬盘开机未挂载】
- 实验吧-天下武功唯快不破
- java this final_JAVA中的this,final,surper的用法
- 4.1 人工智能的发展趋势
- 数据挖掘机器学习[六]---项目实战金融风控之贷款违约预测
- 通过ip查看主机名和MAC地址的cmd命令
- 区间类动态规划(dp)
- 第一个被赋予公明身份的机器人_世界首位获公民身份机器人索菲亚,称要结婚生子毁灭人类...