Flask API TypeError: Object of type 'Response' is not JSON serializable

错误代码:

session['image'] = str
    return response

如果str是一个变量,此处不报错,如果没有str,就是系统带的clas str,这里就会异常,原因是json序列化异常。

@auth.route('/code')
def get_code():
    image, str = validate_picture()
    # 将验证码图片以二进制形式写入在内存中,防止将图片都放在文件夹中,占用大量磁盘
    buf = BytesIO()
    image.save(buf, 'jpeg')
    buf_str = buf.getvalue()
    # 把二进制作为response发回前端,并设置首部字段
    response = make_response(buf_str)
    response.headers['Content-Type'] = 'image/gif'
    # 将验证码字符串储存在session中
    session['image'] = str
    return response

Flask API TypeError: Object of type 'Response' is not JSON serializable相关推荐

  1. TypeError: Object of type set is not JSON serializable

    今天运行flask项目突然报TypeError: Object of type set is not JSON serializable错误,上网搜了一下 该对象是set形式,json序列不支持,回到 ...

  2. 返回 JSON 格式数据报错:TypeError: Object of type set is not JSON serializable

    在做 flask 项目的时候需要返回一个 JSON 数据,运行的过程中却报错:TypeError: Object of type set is not JSON serializable 报错位置如下 ...

  3. 成功解决TypeError: Object of type 'ndarray' is not JSON serializable

    解决问题 TypeError: Object of type 'ndarray' is not JSON serializable 解决方法 def default(self, obj):if isi ...

  4. 【文件处理】——字典写入json文件或TXT文件,读取文件中的字典TypeError: Object of type ‘ndarray‘ is not JSON serializable错误解决方法

    目录 一.将字典写入json文件 二.json文件中读取字典 三.将字典写入TXT文件中 四.从TXT中读取字典 五.解决字典含数组存入json文件失败的方法 1.存入前将数组变成列表 2.扩展类方法 ...

  5. labelme2coco问题:TypeError: Object of type 'int64' is not JSON serializable

    最近在做MaskRCNN 在自己的数据(labelme)转为COCOjson格式遇到问题:TypeError: Object of type 'int64' is not JSON serializa ...

  6. TypeError: Object of type 'datetime' is not JSON serializable

    json序列化时间对象的时候报错: TypeError: Object of type 'datetime' is not JSON serializable 解决办法 重写json序列化类 # -* ...

  7. Python TypeError: Object of type ‘Decimal‘ is not JSON serializable 类型错误 无法json

    场景:今天使用python 查询了一个MYSQL 数据库的信息  数据库的字段为decimal 类型 我将结果进行json.dumps 报错 TypeError: Object of type 'De ...

  8. 记录:TypeError: Object of type int32 is not JSON serializable。

    rect_list = list()...rect_list.append(rect1)rect_list.append(rect2)...rsp = {'rect-list': rect_list} ...

  9. TypeError: Object of type ‘TrackedArray‘ is not JSON serializable

    如果x是Object of type 'TrackedArray',那么这里使用x.tolist()可以解决问题,转化为list

最新文章

  1. java虚拟机改装_java虚拟机线上配置
  2. 小学生 python教程-Python最佳学习路线图
  3. Love = Accounting
  4. java linux so
  5. Matlab图像剪切,超出图像区域指定颜色填充
  6. Linux运维工程师面试题第三套
  7. Linux修改hostname的几种方式,及遇到的问题
  8. 将(*)的ASCII码2AH送入内存段1000H开始的100个单元中
  9. python split函数 空格_最易懂的Python新手教程:从基础语法到代码详解
  10. python杨辉三角_python中的部分高级特性
  11. mysql5.6.35源码安装记录
  12. 标准C语言第四版答案第十章,谭浩强C语言 第十章课后习题
  13. 如何理解熵、交叉熵、KL散度、JS散度
  14. mysql和oracle的字符串拼接_Oracle和Mysql中的字符串的拼接
  15. DDS产生双频正弦波及叠加
  16. 加一(python)
  17. 用电脑怎么快速抠图?怎么把图片抠成透明背景?
  18. Kindle系列(二)免费电子书籍
  19. Python 位操作符(Bitwise)
  20. RIGOL DS1102D示波器说明及纹波、上电脉冲、时序测试

热门文章

  1. TCP/IP详解--第九章
  2. 使用SQLyog无法连接到MySQL,error code 2013
  3. python elementtree 父节点_python-访问ElementTree节点父节点
  4. Java接收多台设备发送消息_FCM(Firebase Cloud 消息传递)发送到多个设备
  5. mysql主从复制延时性问题_MySQL主从同步延迟原因及解决办法
  6. echarts饼图解析html标签,解决echarts中饼图标签重叠的问题
  7. PHP 中华如何用命令连接数据库,选择MySQL数据库的命令以及PHP脚本下的操作方法...
  8. linux配置选项大全,Linux下的十项实用“sudo”配置选项
  9. php 析构不执行,PHP析构方法 __destruct() 不触发的两个解决办法
  10. html语言剖析,HTML语言剖析(十三) 其他标记