TypeError: Object of type datetime is not JSON serializable

一、原因分析

在python中出现了这个错误的根本原因是:json.dumps()不能对{}的datetime时间格式数据进行转化。

dumps的本来功能是将dict转化为str格式,并不支持转化时间,其实出现这个问题的解决方式很简单。

二、解决方式
 将时间数据转化为字符串,示例: str((datetime.datetime.now()))

在特殊的时间格式数据加上str(),强行转换为字符串,然后再执行请求即可解决错误。

原文地址:https://www.cnblogs.com/xiaoguan-bky/p/14600795.html