简体   繁体   中英

TypeError: Object of type set is not JSON serializable This is the error I'm getting

from flask import Flask, request
from flask_restful import Api, Resource
import db_conn
app = Flask(__name__)
api = Api(app)


class save_data(Resource):
def post(self):
    conn = None
    cur = None
    request_data = request.get_json()
    try:
        conn = db_conn()
        cur = conn.cursor()
        save_name = request_data["save_name"]
        save_data = request_data["data"]
        query = "insert into OMS_ORD_DATA.OMS_ALLC_SCENARIOS (TEMPLATE, DIVISION_ID ,CREATION_DATE, CREATED_BY " \
                "VALUES  ({} , '1', SYSDATE, '-4')".format(save_data)
        cur.execute(query)
        lines = cur.fetchall()
        print(lines)
        return {"msg":"Data Saved Success"}
    except Exception as e:
        return {"Error: ", str(e)}
    finally:
        if cur is not None:
            cur.close()
        if conn is not None:
            conn.close()

api.add_resource(reload_data, '/reload_data')
if __name__ == '__main__':
  app.run(host="localhost", port=8888, debug=True)

I want to insert the JSON data from the API input into the oracle table, API input:

{
"save_name":"ETL FULLREFRESH load",
"data":[
    {
      "name":"ETL",
      "priority":1
    },
    {
      "name":"Full Refresh",
      "priority":1
    },
    {
      "name":"POPM",
      "priority":2
    }
     ]
}

TypeError: Object of type set is not JSON serializable This above error is popping up, I tried using q1 = {'data': [dict(zip(tuple(query.keys()), i)) for i in query.cur]}

Any help or suggestions will be very helpful, thanks

you need to add the resource save_data ,

api.add_resource(save_data, '/save_data')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM