首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从数据库赋值变量

从数据库赋值变量
EN

Stack Overflow用户
提问于 2020-12-10 03:13:44
回答 1查看 100关注 0票数 0

我正在尝试用rfid和密码来创建python智能锁,而不是常规的"1234",我在PyOTP Libray中使用Time。

目前,我一直在研究如何使用来自表用户的secret数据在if函数中分配secret变量值。

如何将secret值从users表分配给变量secret

IF函数

代码语言:javascript
复制
print("Place card near scanner")
id, text = reader.read()
cursor.execute("Select id From users Where rfid_uid="+str(id))
result = cursor.fetchone()

if cursor.rowcount > = 1:
   print("Welcome\nType the code from your authenticator app")
   secret = ('''The data from "secret" in users table''')

用户表

代码语言:javascript
复制
+----+--------------+-------------+------------------+---------------------+
| id | rfid_uid     | name        | secret           | created             |
+----+--------------+-------------+------------------+---------------------+
|  1 | 939940479059 | Blue Dongle | LONGSTRINGOFCODE | 2020-12-10 09:07:34 |
+----+--------------+-------------+------------------+---------------------+

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-12-10 05:04:59

如果修改select语句,除了选择secret之外,还应该能够选择id

代码语言:javascript
复制
print("Place card near scanner")
id, text = reader.read()
cursor.execute("SELECT id, secret FROM users WHERE rfid_uid="+str(id))
result = cursor.fetchone()

if cursor.rowcount >= 1:
    print("Welcome\nType the code from your authenticator app")
    secret = result[1]
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65228007

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档