1.TypeError: must be str, not bytes
1.TypeError: must be str, not bytes错误:
解答: 写文件处 open(filename, 'w').write 应该写为 open(filename, 'wb').write
2.当文本文件里面有中文时,需要进行编码转换,(在网上查了很多都不行)
with open("C://ch.js", encoding="utf-8") as data1:
for oneLine in data1:
print(oneLine)
编码转换:content = str(open(filepath).read(),'gbk').encode('utf8')
当输出多一个b时加个decode(‘utf-8’)即可
1.TypeError: must be str, not bytes的更多相关文章
- python TypeError: must be str, not bytes错误
TypeError: must be str, not bytes错误: 解答: 写文件处 f=open(filename, 'w')应该写为 open(filename, 'wb') 读文件时 f= ...
- TypeError: write() argument must be str, not bytes报错原因及Python3写入二进制文件方法
Python2随机写入二进制文件: with open('/python2/random.bin','w') as f: f.write(os.urandom(10)) 但使用Python3会报错: ...
- 关于TypeError: strptime() argument 1 must be str, not bytes解析
关于TypeError: strptime() argument 1 must be str, not bytes解析 在使用datetime.strptime(s,fmt)来输出结果日期结果时, ...
- Python 读写文件 中文乱码 错误TypeError: write() argument must be str, not bytes+
今天写上传文件代码,如下 def uploadHandle(request): pic1=request.FILES['pic1'] picName=os.path.join(settings.MED ...
- Python之scrapy框架之post传输数据错误:TypeError: to_bytes must receive a unicode, str or bytes object, got int
错误名:TypeError: to_bytes must receive a unicode, str or bytes object, got int 错误翻译:类型错误:to_bytes必须接收u ...
- Python错误TypeError: write() argument must be str, not bytes
2016-07-03 20:51:25 今天使用Python中的pickle存储的时候出现了以下错误: TypeError: write() argument must be str, not byt ...
- TypeError: write() argument must be str, not bytes报错
TypeError: write() argument must be str, not bytes 之前文件打开的语句是: with open('C:/result.pk','w') as fp: ...
- HTTPResponse object — JSON object must be str, not 'bytes'
http://stackoverflow.com/questions/24069197/httpresponse-object-json-object-must-be-str-not-bytes HT ...
- Python中的编码问题(encoding与decode、str与bytes)
1 引言 在文件读写及字符操作时,我们经常会出现下面这几种错误: TypeError: write() argument must be str, not bytes AttributeError: ...
随机推荐
- Redis Quick Start [熟练版]
一.下载解压 wget http://download.redis.io/redis-stable.tar.gztar xvzf redis-stable.tar.gzcd redis-stable ...
- Java® Language Specification
Java™ Platform, Standard Edition 8 API Specification http://docs.oracle.com/javase/8/docs/api/ The J ...
- [转]程序集之GAC---Global Assembly Cache
本文转自:http://www.cnblogs.com/jhxk/articles/2564295.html 1.什么是GAC?GAC解决什么问题? GAC全称为: Global Assembly C ...
- 树莓派3下安装TL-WN722N无线网卡驱动
最近在搞树莓派,我的是国产的树莓派3卡片电脑,想整成一个无线加有线的路由器(树莓派3.TL-WN722N无线网卡.集线器)或者是搭个web认证的WIFI钓鱼热点玩玩. 一开始就遇到问题了,连无线网卡的 ...
- Java垃圾收集调优实战
1 资料 JDK5.0垃圾收集优化之--Don't Pause(花钱的年华) 编写对GC友好,又不泄漏的代码(花钱的年华) JVM调优总结 JDK 6所有选项及默认值 2 GC日志打印 GC调 ...
- Mysql报Packet for query is too large (1040 > 1024)错误
Linux下mysql 报Packet for query is too large (1040 > 1024)错误的解决方法 项目之前一直正常运行,这几天突然一直提示查询出错,看了下日志发现提 ...
- 全面了解SQL
很多程序员认为SQL是一头难以驯服的野兽.它是为数不多的声明性语言之一,也因为这样,其展示了完全不同于其他的表现形式.命令式语言. 面向对象语言甚至函数式编程语言(虽然有些人觉得SQL 还是有些类似功 ...
- 关于 Kafka offset
查询topic的offset的范围 用下面命令可以查询到topic:Mytopic broker:SparkMaster:9092的offset的最小值: bin/kafka-run-class.sh ...
- 如何将图片嵌入到Html中
将图片内嵌入到Html中,最好的方法就是用Base64 string.例如:<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUg ...
- artemplate模板
artTemplate 介绍 最近使用了一款模板,学习成本比较低,性能也不错.觉得很好用,所以推荐给大家. artTemplate 是新一代 javascript 模板引擎,它采用预编译方式让性能有了 ...