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

  

  

原文地址:https://www.cnblogs.com/AndyChen2015/p/7493332.html