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的更多相关文章

  1. python TypeError: must be str, not bytes错误

    TypeError: must be str, not bytes错误: 解答: 写文件处 f=open(filename, 'w')应该写为 open(filename, 'wb') 读文件时 f= ...

  2. TypeError: write() argument must be str, not bytes报错原因及Python3写入二进制文件方法

    Python2随机写入二进制文件: with open('/python2/random.bin','w') as f: f.write(os.urandom(10)) 但使用Python3会报错: ...

  3. 关于TypeError: strptime() argument 1 must be str, not bytes解析

    关于TypeError: strptime() argument 1 must be str, not bytes解析   在使用datetime.strptime(s,fmt)来输出结果日期结果时, ...

  4. Python 读写文件 中文乱码 错误TypeError: write() argument must be str, not bytes+

    今天写上传文件代码,如下 def uploadHandle(request): pic1=request.FILES['pic1'] picName=os.path.join(settings.MED ...

  5. 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 ...

  6. 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 ...

  7. TypeError: write() argument must be str, not bytes报错

    TypeError: write() argument must be str, not bytes 之前文件打开的语句是: with open('C:/result.pk','w') as fp: ...

  8. HTTPResponse object — JSON object must be str, not 'bytes'

    http://stackoverflow.com/questions/24069197/httpresponse-object-json-object-must-be-str-not-bytes HT ...

  9. Python中的编码问题(encoding与decode、str与bytes)

    1 引言 在文件读写及字符操作时,我们经常会出现下面这几种错误: TypeError: write() argument must be str, not bytes AttributeError: ...

随机推荐

  1. dojo和jquery混合使用

    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/dojo/1.7 ...

  2. (一)JQuery动态加载js的三种方法

    Jquery动态加载js的三种方法如下: 第一种: $.getscript("test.js"); 例如: <script type="text/javascrip ...

  3. android事件分发

    1). android对事件分发的顺序为:Activity--->PhoneWindow--->DecorView--->yourView; 2). android控件对事件处理的优 ...

  4. Android-HttpsURLConnectionHelp工具类

    Java版(HttpURLConnection)Https请求工具类 public class HttpsURLConnectionHelp { /** * 加密协议 */ public static ...

  5. Postgresql 日志收集

    PG安装完成后默认不会记录日志,必须修改对应的(${PGDATA}/postgresql.conf)配置才可以,这里只介绍常用的日志配置. 1.logging_collector = on/off - ...

  6. 在TFS 2013的敏捷组合管理中添加积压工作

    在TFS提供的三套默认模板中,组合管理(Portfolio Management)只包含功能(Feature)和要求这个两个积压工作.你可以参考下面的文档,学会如何在积压工作中添加额外的工作项类型. ...

  7. C# defualt关键字默认值用法

    默认值表达式生成类型的默认值. 默认值表达式在泛型类和泛型方法中非常有用. 使用泛型类和泛型方法时出现的一个问题是,如何在无法提前知道以下内容的情况下将默认值赋值给参数化类型 T: T 是引用类型还是 ...

  8. 'Install app for SharePoint': Sideloading of apps is not enabled on this site

    http://blog.lekman.com/2012/11/sharepoint-2013-sideloading-of-apps-is.html Solution: You need to ena ...

  9. java学习笔记—校验码的实现(15)

    校验码的出现主要的任务是解决表单的重复提交问题. public void doGet(HttpServletRequest request, HttpServletResponse response) ...

  10. 一篇文章搞懂Linux安全!

    Linux是开放源代码的免费正版软件,同时也是因为较之微软的Windows NT网络操作系统而言,Linux系统具有更好的稳定性.效率性和安全性. 在Internet/Intranet的大量应用中,网 ...