Python Insert to SQL Server


I am very new to Python and I am trying to insert data from a Python call to a SurveyMonkey api. I’ve gotten the data I want and have assigned the json returned to a python variable. I need to insert the entire json document in this variable to a SQL Server Column (nvarcharmax) so I can parse it further. I have tried the following code for my insert:

conn = pyodbc.connect(‘Driver={SQL Server};’

cursor = conn.cursor()
Insert into SurveyList (Json)

When I run this I get

pyodbc.ProgrammingError: (‘42S22’, “[42S22] [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid column name ‘response_json’. (207) (SQLExecDirectW)”)

The python variable this json is stored in is called response_json and the SQL column is called Json. I don’t know why it thinks the input variable is a column when this is the python variable with the json values I want. I can print this variable and see the data I want.  What am I doing wrong here? Thanks

Following additional reasearch, I have tried the following code:

Sql_insert_query = “”"INSERT INTO SurveyList (Json)
VALUES (?) “”"

recordTuple = response_json
cursor.execute(Sql_insert_query, recordTuple)

This changes the error to the following:

File “C:/Users/ITadmin/PycharmProjects/untitled/”, line 35, in <module>
cursor.execute(Sql_insert_query, recordTuple)
pyodbc.ProgrammingError: (‘Invalid parameter type. param-index=0 param-type=dict’, ‘HY105’)

The data being returned is a json document from a REST API stored in a Python variable called response_json. I’m not sure what the correct parameter type is or how to specify it. Any help woul dbe appreciated.

Found somehting that worked. I’m posting the entire thing in case any newbie like me needs help to pull data from a REST API and  get it into SQL as this took me awhile to get it going

import requests
import pyodbc
import json

client = requests.session()

headers = {
“Authorization”: “bearer %s” % “apikey”,
“Content-Type”: “application/json”

data = {}

HOST = “

SURVEY_LIST_ENDPOINT = “/v3/surveys/”


response = client.get(uri, headers=headers)

response_json = response.json()

conn = pyodbc.connect(‘Driver={SQL Server};’

cursor = conn.cursor()
cursor.execute(“Insert Into Table (COlumnName) values (?)”, (json.dumps(variablename),))