我可以添加2020
之类的数字,但是不能将我的密钥添加到sqlite3数据库。我的私钥就是这样的833a7a763c15cc33e0d2157a1b8464047e9f2ad8f3e84f02f594a99a590f1ac5
如果我添加私钥,则会收到此错误。我是python的新手,我无法找出问题所在。我已经修复了3个多小时的错误。
这是错误消息
Traceback (most recent call last):
File "C:/Users/hp/Downloads/SimpleCoin-master/SimpleCoin-master/simpleCoin/recent.py", line 55, in <module>
tran()
File "C:/Users/hp/Downloads/SimpleCoin-master/SimpleCoin-master/simpleCoin/recent.py", line 38, in tran
cursor.execute(sql_cmd)
sqlite3.OperationalError: unrecognized token: "833a7a763c15cc33e0d2157a1b8464047e9f2ad8f3e84f02f594a99a590f1ac5"
这是我的代码
import sqlite3, time
from datetime import datetime
def st():
with sqlite3.connect("AA1.db") as db:
cursor = db.cursor()
# create table
cursor.execute('''
CREATE TABLE IF NOT EXISTS transactions(
private_k VARCHAR(250) NOT NUll,
sender_k VARCHAR(250) NOT NULL,
receiver_k VARCHAR(250) NOT NULL,
c_amount INTEGER NOT NULL,
dNt TEXT NOT NULL);
''')
# insert values to table from user input
pri_key = input('Sender Private Key: ')
pub_key = input('Sender Public Key: ')
r_pub_k = input('Receiver Public Key: ')
c_amount = input('Amount: ')
dt_for = datetime.now().strftime("%B %d, %Y %I:%M%p")
cursor.execute("""
INSERT INTO transactions(private_k, sender_k, receiver_k, c_amount, dNt)
VALUES (?,?,?,?,?)
""", (pri_key, pub_key, r_pub_k, c_amount, dt_for))
db.commit()
# print("Data entered successfully")
def tran():
private_key = input("Enter your private key: ")
with sqlite3.connect("AA1.db") as db:
cursor = db.cursor()
sql_cmd = 'SELECT * FROM transactions WHERE private_k={}'.format(private_key)
cursor.execute(sql_cmd)
for row in cursor.fetchall():
#pri_key = row[0]
pub_key = row[1]
r_pub_k = row[2]
c_amount = row[3]
dt_for = row[4]
#print(pri_key)
print('-------------------------------')
print("From:", pub_key)
print("To:", r_pub_k)
print("Amount: ", c_amount)
print("Date and Time: ", dt_for)
print('-------------------------------')
st()
tran()