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()

  

  

posted @ 2017-09-08 10:32  猪快跑  阅读(424)  评论(0编辑  收藏  举报