成功解决TypeError: a bytes-like object is required, not 'str'
解决 not is 成功 object required like Str
2023-09-14 09:04:51 时间
成功解决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(",")
大功告成!
相关文章
- oracle library is not loaded和ORA-12523的错误分析与解决
- nginx: 405 not allowed问题解决方法
- maven配置报错以及The JAVA_HOME environment variable is not defined correctly的解决方法
- Navicat Premium 12连接Oracle时提示oracle library is not loaded的问题解决
- Eclipse中Editor does not contain a main type 解决方法
- 【已解决】Redis连接——Could not connect to Redis at 127.0.0.1:6379: Connection refused[通俗易懂]
- 使用GROUP BY 发生错误 SELECT list is not in GROUP BY clause .......... 解决
- Navicat Premium 12连接Oracle时提示oracle library is not loaded的问题解决「建议收藏」
- zip压缩报错解决:zip warning: name not matched: xxx/xxx/xxx
- 一分钟解决 The server selected protocol version TLS10 is not accepted 问题
- [MySQL]解决mysql数据库连接报错:is not allowed to connect to this mysql server
- solr错误【已解决】:solr is not an explicit field and doesn't match a dynamicField
- 【已解决】ShardingSphere 使用记录,ShardingException: Can not update sharding key, logic table: [user_log]解决
- adb出错 adb not responding 解决方法
- 解决The HTTP request is not acceptable for the requested resource
- 解决idea登录github出现的invalid authentication data 404 not found以及登录 token 失效
- DEV c++点击f5刷新运行代码,会闪退,点击运行却不会闪退。怎么解决?
- 解决:无法将“php”项识别为 cmdlet、函数、脚本文件或可运行程序的名称
- 解决 nvcc: command not found-(已配置环境变量但报这个提示)
- 【致敬嵌入式攻城狮第2期活动预热征文】解决瑞萨RA2E1开发板在RT-Thread的版本中编译报错 error: ‘board_cfg.h‘ file not found
- xxx is not in the sudoers file.This incident will be reported.的解决方法详解程序员
- mysql创建外键报错的原因及解决(can't not create table)
- 【最快捷】解决Navicat 出错:1130-host . is not allowed to connect to this MySql server,MySQL详解数据库
- 解决json结合struts2时,Class org.apache.struts2.json.JSONWriter can not access a member of * 的问题详解编程语言
- acle not inOracle IN与NOT IN的比较(oraclein和or)
- 解决SQLServer表丢失的简易方法(sqlserver表丢失)
- MySQL数据库如何使用不等于操作符和 来代替IS NOT操作符(mysql不等于is)
- 解决Redis连接失败的小技巧(redis连接连接失败)
- 深入Lumisoft.NET组件开发碰到乱码等问题的解决方法
- Firefox中使用outerHTML的2种解决方法
- JSONP跨域GET请求解决Ajax跨域访问问题