我正在使用带有sqlite3的python 2.7
我已经创建了一个空表和一个函数来检查表是否为空它获取当前pc的mac地址并将其存储在表中,每次程序工作时它都有效,如果表是不是空它调用另一个获取当前mac的函数并将其与存储在表中的函数进行比较,如果它不相同则关闭程序, 这是代码:
def active():
from uuid import getnode as get_mac
mac = get_mac()
name = 666
conn = sqlite3.connect('storage/container.db')
conn.row_factory = lambda c, row: row[0]
c = conn.cursor()
c.execute("SELECT COUNT(*) FROM mac")
count = c.fetchall()[0]
conn.close()
if count == 0:
conn = sqlite3.connect('storage/container.db')
conn.row_factory = lambda c, row: row[0]
c = conn.cursor()
c.execute("INSERT INTO mac (name, macAddress) VALUES (?, ?)", (name, mac, ))
conn.commit()
conn.close()
else:
checking()
def checking():
from uuid import getnode as get_mac
mac = get_mac()
conn = sqlite3.connect('storage/container.db')
conn.row_factory = lambda c, row: row[0]
c = conn.cursor()
c.execute("SELECT macAddress FROM mac WHERE name = 666")
table_mac = c.fetchall()[0]
if mac == table_mac:
critical_title1 = 'أهلاً بك '
critical_title = critical_title1.decode('utf-8')
critical_msg1 = "تم تأكيد صلاحية النسخة للإستخدام "
critical_msg = critical_msg1.decode('utf-8')
QtGui.QMessageBox.information(mainWindow, critical_title, critical_msg)
else:
critical_title1 = 'خطأ'
critical_title = critical_title1.decode('utf-8')
critical_msg1 = "لا يمكنك إستخدام البرنامج من دون شراء نسختك الخاصة"
critical_msg = critical_msg1.decode('utf-8')
QtGui.QMessageBox.critical(mainWindow, critical_title, critical_msg)
sys.exit()
一切都很顺利,程序已经捕获了mac地址,然后将其添加到表中,但是,在所有情况下,它都显示了在它之后关闭程序的错误..忽略了if-else
语句应该停止显示错误
我认为问题在于:
if mac == table_mac:
critical_title1 = 'أهلاً بك '
critical_title = critical_title1.decode('utf-8')
critical_msg1 = "تم تأكيد صلاحية النسخة للإستخدام "
critical_msg = critical_msg1.decode('utf-8')
QtGui.QMessageBox.information(mainWindow, critical_title, critical_msg)
else:
critical_title1 = 'خطأ'
critical_title = critical_title1.decode('utf-8')
critical_msg1 = "لا يمكنك إستخدام البرنامج من دون شراء نسختك الخاصة"
critical_msg = critical_msg1.decode('utf-8')
QtGui.QMessageBox.critical(mainWindow, critical_title, critical_msg)
sys.exit()
没有回溯错误的主要问题
尽管符合条件if mac == table_mac:
,它只显示最后的其他语句
答案 0 :(得分:0)
问题是我试图从我刚刚更改的第一个函数中调用第二个函数
else:
checking()
到pass
,然后为这两个函数添加自动运行命令,效果很好
active()
checking()