TypeError: write() argument must be str, not bytes

Posted Andy.Chen

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了TypeError: write() argument must be str, not bytes相关的知识,希望对你有一定的参考价值。

w文件打开以 ‘二进制‘  方式:

with open(‘teacher.html‘,‘wb+‘) as f:
    f.write(response.body)

 

要写入"中文",防止乱码:

fo = open("temp.txt", "wb+")
str = ‘中文‘
str = str.encode(‘utf-8‘)
fo.write(str)
fo.close()

  

  

以上是关于TypeError: write() argument must be str, not bytes的主要内容,如果未能解决你的问题,请参考以下文章

Python错误TypeError: write() argument must be str, not bytes

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

TypeError: write() argument must be str, not bytes

Python 3 TypeError: must be str, not bytes with sys.stdout.write()

Python错误TypeError: write() argument must be str, not bytes

如何解决 TypeError: request.write is not a function