我正在尝试使用python将一些数据库字段插入SQLite DB。我不断收到以下错误:
ValueError: operation parameter must be str
Run Code Online (Sandbox Code Playgroud)
下面是我的代码。
import sqlite3
conn = sqlite3.connect("pass.db")
c = conn.cursor()
#Create table password
table_create_statement = "create table if not exists password(id integer primary key, site text, pass text);"
c.execute(table_create_statement)
#Promt user to input entry
sites = str(raw_input("Enter name of the sites: "))
password = str(raw_input("Enter password: "))
#SQL statement to insert the new entry
sql_statement = "insert into password values(?, ?, ?);",(None, sites, password)
c.execute((sql_statement))
connection.commit()
print("Password entered successfully")
Run Code Online (Sandbox Code Playgroud)
输出:
Enter name of …Run Code Online (Sandbox Code Playgroud)