datetime is not json serializable
python, datetime is not json serializable
import datetime def json_serial(obj):
"""JSON serializer for objects not serializable by default json code""" if isinstance(obj, (datetime.datetime, datetime.date)):
return obj.isoformat()
raise TypeError("Type %s not serializable" % type(obj))
示例代码:
from datetime import datetime
from json import dumps print dumps(datetime.now(), default=json_serial)
ref:https://stackoverflow.com/questions/11875770/how-to-overcome-datetime-datetime-not-json-serializable
datetime is not json serializable的更多相关文章
- python:datetime.datetime is not JSON serializable 报错问题解决
问题: 项目使用django开发,返回的数据中有时间字段,当json.dumps()时提示:datetime.datetime is not JSON serializable 解决: import ...
- python datetime.datetime is not JSON serializable
1.主要是python list转换成json时对时间报错:datetime.datetime(2014, 5, 23, 9, 33, 3) is not JSON serializable. 2. ...
- 【django json.dumps 报错】 datetime.datetime is not JSON serializable
django 中,json.dumps 无法直接转译 datetime 类型的值. 找了无数方法,找到一个最优.最简洁的解决办法: json.dumps(results, indent=4, sort ...
- TypeError: Object of type 'datetime' is not JSON serializable
我的描述:我在flask框架中引用orm查数据库并返回数据,出现此类问题,如下图: 解决方案: 1.从表面意思看,就是说datetime时间类型无法被序列化.于是我百度了网上的同事的解答,大多说是时间 ...
- How to overcome “datetime.datetime not JSON serializable” in python?
json.dumps(datetime.now) 意思是datetime.now不可json序列化,解决办法是转化成str或者加一个参数 cls=xxx 详细见: http://stackoverfl ...
- celery 4.1下报kombu.exceptions.EncodeError: Object of type 'bytes' is not JSON serializable 处理方式
#python代码如下 from celery import Celeryimport subprocess app = Celery('tasks', broker='redis://localho ...
- Object of type 'ListSerializer' is not JSON serializable “listserializer”类型的对象不可JSON序列化
Object of type 'ListSerializer' is not JSON serializable “listserializer”类型的对象不可JSON序列化 一般原因为 序列化的对象 ...
- TypeError: Object of type 'int64' is not JSON serializable
错误类型:TypeError: Object of type 'int64' is not JSON serializable 错误场景:对Numpy和Pandas结果进行json.dumps报错 错 ...
- TypeError: Object of type 'int32' is not JSON serializable ——已解决
将模型用flask封装,返回json时报错:TypeError: Object of type 'int32' is not JSON serializable 网上搜索出的解决方案:重写json.J ...
随机推荐
- [转]Win 10 的 Win 按键没反应
来自:http://www.pc0359.cn/article/win10/66397.html 方法步骤: 1.首先我们需要将任务管理器运行出来.方法有两种,第一种:使用鼠标右键单击屏幕下方的任务栏 ...
- Maven的classifier作用
classifier可以是任意的字符串,用于拼接在GAV之后来确定指定的文件. 可用于区分不同jdk版本所生成的jar包 <dependency> <groupId>net.s ...
- The type android.support.v4.view.ScrollingView cannot be resolved. It is indirectly referenced from
前几天另一个项目使用RecyclerView控件,引用类库然后继承一切都很顺序 详细:http://www.cnblogs.com/freexiaoyu/p/5022602.html 今天打算将另一个 ...
- maven使用笔记--在父pom中声明过的jar可以被继承,使子项目不用写版本号由父pom控制
将dependencies放到dependencyManagement中,如下: [html] view plaincopy <dependencyManagement> <depe ...
- [UE4]透明按钮
Background Color的透明度设置为0,就能让按钮背景完全透明,但是按钮里面的子控件并不会跟着透明
- PostgreSQL手动主从切换
主从切换操作: 1>主库宕机或者测试主备切换情况下停掉主库:systemctl stop postgres 从库会报日志错误信息:[root@db02 /]# cd /var/postgresq ...
- .net百度编辑器的使用
1.前端引用 <%@ Page ValidateRequest="false" Language="C#" AutoEventWireup="t ...
- CentOS、Ubuntu、Debian简析
Centos .Ubuntu.Debian 三个Linux都是非常优秀的系统,开源的系统,也分付费的商业版和免费版,下面简单比较这三种系统. Centos系统 非常多的商业公司部署在生产环境上的服务器 ...
- 使用vim时生成的.swp文件
1. 在使用vim时,退出编辑后,发现生成了swp文件,如下: 发现用vim打开一个文件时,都会产生一个.swp的隐藏文件(即文件名.开头的),这个文件是一个临时交换文件,用来备份缓冲区中的内容,用于 ...
- 迭代器 -> 固定的思路. for循环
一个数据类型中包含了__iter__函数表示这个数据是可迭代的 dir(数据): 返回这个数据可以执行的所有操作 判断迭代器和可迭代对象的方案(野路子) __iter__ 可迭代的 __iter__ ...