I am trying to return an outfit from m RDS database. The dte fields are all formatted in DATETIME which is causing me to get the following error:
TypeError: datetime.datetime(2012, 8, 8, 21, 46, 24, 862000) is not JSON serializable
How can I get around this?
heres my code:
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