我目前正在尝试使用python与我的SQL数据库进行交互,当我运行代码时出现这个非常奇怪的错误,错误是:
“Traceback(最近一次调用最后一次):文件”/ media / james / James的HDD / QE Things / Computing CourseWork /新增和改进使用这些ONES / testdb.py“,第16行,在sql = str中(”INSERT INTO Server_Log(LogID,Log)VALUES“,(server_log3))TypeError:不支持解码str”。
这是我的代码:
import sqlite3 as db
con = None
server_log=[["message_redirect","Dan"],["message_redirect","James"]]
for i in range(0,len(server_log)):
server_log1=server_log[i][0]
server_log2=server_log[i][1]
print(server_log1)
print(server_log2)
server_log3=server_log1+"," +server_log2
print(server_log3)
sql=str("INSERT INTO Server_Log (LogID, Log) VALUES", (server_log3))
try:
con = db.connect('data.db',isolation_level=None)
cur = con.cursor()
cur.execute(sql)
data = cur.fetchone()
#for data in data:
print(data)
finally:
if con:
con.close()
print("done")