我如何获取表上的值并将其保存到变量中

import sqlite3
from hashlib import sha256


conn = sqlite3.connect('pass_manager.db')
connect = input("Es tu primera vez en la app?\n")
conn.execute('''CREATE TABLE IF NOT EXISTS KEYAD
            (PASS_KEY TEXT PRIMARY KEY NOT NULL);''')
if connect == "si":
    contraseña = input("Ingresa tu contraseña\n")
    ADMIN_PASSWORD = contraseña
    conn.execute('''INSERT INTO KEYAD(PASS_KEY) VALUES (?)''', (contraseña,))

else:
    conn.execute('''SELECT PASS_KEY FROM KEYAD''')
    contraseña = conn.fetchone()
`I want to get the value from the table and save into the variable to check if the login its ok`
    ADMIN_PASSWORD = contraseña


connect = input("Cual es tu contraseña?\n")

while connect != ADMIN_PASSWORD:
    connect = input("Cual es tu contraseña?\n")
    if connect == "q":
        break


我得到这个错误

文件“ j:/ Proyectos y Trabajos / Python / PythonProjects-master / PasswordManager / password_manager.py”,第17行,在     相反= conn.fetchone() AttributeError:'sqlite3.Connection'对象没有属性'fetchone'

评论
  • Hood
    Hood 回复

    您必须在游标而不是连接上调用fetchone

        cur = conn.cursor()
        cur.execute('''SELECT PASS_KEY FROM KEYAD''')
        contraseña = cur.fetchone()