gpt4 book ai didi

python - AWS Lambda TypeError : datetime. datetime(2012, 8, 8, 21, 46, 24, 862000) 不是 JSON 可序列化的

转载 作者:行者123 更新时间:2023-11-28 21:48:18 25 4
gpt4 key购买 nike

<分区>

我正在尝试从 RDS 数据库中返回一套服装。 dte 字段全部采用 DATETIME 格式,这导致我收到以下错误:

TypeError: datetime.datetime(2012, 8, 8, 21, 46, 24, 862000) is not JSON serializable

我该如何解决这个问题?

这是我的代码:

import pymysql
import json
from rds import *

#rds settings
host = rds_host
name = rds_name
password = rds_password
db_name = rds_db_name
port = rds_port

try:
conn = pymysql.connect(host = host, user=name, passwd=password, db=db_name, connect_timeout=5)

except:
raise Exception('Database Error: The server encountered an unexpected condition which prevented it from fulfilling the request.')


def handler(event, context):

cur = conn.cursor(pymysql.cursors.DictCursor)
#selects a user from the database
query = "SELECT * FROM Outfits WHERE outfit_id = '" + event['outfitId'] + "' LIMIT 1"
#runs the SQL query
try:
cur.execute(query)
except:
raise Exception('Internal Error: The server encountered an unexpected condition which prevented it from fulfilling the request.')

#stores the downloaded record into the user variable
rows = cur.fetchone()
return result

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com