python ‘str’ does not support the buffer interface解决办法

来源:互联网 发布:注册淘宝账号 编辑:程序博客网 时间:2024/05/18 13:23

python ‘str’ does not support the buffer interface解决办法

  • 问题背景

    使用Requests来获取网络数据

    response = request.get(url)

    当将输出数据或将数据写入文件时,出现错误

    with open("output.html", "wb") as file:    file.write(response.text)

    错误原因

  • 解决办法

    需要将数据类型进行转换,代码如下

    with open("output.html", "wb") as file:    file.write(response.text.encode())
阅读全文
0 0