Sqlite3 error message in Python. InterfaceError

sqlite3 error message in Python:

the code is as follows:

df = pandas.DataFrame(newsdetail)
df.to_excel("news1.xls")
import sqlite3
with sqlite3.connect("news.sqlite") as db:
    df.to_sql("news",con = db)
    df2 = pandas.read_sql_query("SELECT * FROM news",con = db)
print(df2)    

what is the problem? Just came into contact with Python, and looked at the code that came out of the tutorial intact.

Feb.28,2021

import pandas
import sqlite3
df = pandas.DataFrame([{'1':2}, {'3':4}])
with sqlite3.connect('news.sqlite') as db:
    df.to_sql('news',con = db)
    df2 = pandas.read_sql_query('SELECT * FROM news',con = db)
-sharp 


df = pandas.DataFrame([{'1':{1:2}}, {'3':{3:4}}])
with sqlite3.connect('news.sqlite') as db:
    df.to_sql('news1',con = db)
    df2 = pandas.read_sql_query('SELECT * FROM news',con = db)
-sharp sqlite3.InterfaceError: Error binding parameter 1 - probably unsupported type
df['1'] object


df = pandas.DataFrame([1, '2'])
with sqlite3.connect('news.sqlite') as db:
    df.to_sql('news2',con = db)
    df2 = pandas.read_sql_query('SELECT * FROM news',con = db)
df[0] object 
cur = db.execute('select * from sqlite_master WHERE type="table" and name= "news2"')
print(cur.fetchone()) -sharp ('table', 'news2', 'news2', 6, 'CREATE TABLE "news2" (\n"index" INTEGER,\n  "0" TEXT\n)') TEXT

according to the answer hint of @ Sword Heart without trace , the reason for this error is finally found.
sqlite3.InterfaceError: Error binding parameter 1-probably unsupported type.
this error should be

df = pandas.DataFrame(newsdetail)

newsdetail (a list of dictionaries) the value of one of the dictionaries is a list, so it prompts an error. It will be normal if you replace the list with a string.

Menu