python - 如何解决“TypeError:只能将str(不是“sqlite3.Cursor”)连接到str”
问题描述
我试图让我的主页在用户登录后显示用户名。我一直先收到这个错误,
sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 14 supplied.
更改(self.current)
为(self.current,)
. 但是,我现在收到此错误,
TypeError: can only concatenate str (not "sqlite3.Cursor") to str
我试图通过将用户设置为"Olá " + str(user)
仅显示的字符串来解决此问题Olá <sqlite3.Cursor object at 0x00000219024FA650>
。
主文件
class HomeScreen(Screen):
usr = ObjectProperty()
email = ObjectProperty()
current = ""
def on_enter(self, *args):
user = cur.execute('SELECT user FROM id WHERE email =?', (self.current,))
self.usr.text = "Olá " + user
print("Olá " + user)
class LoginScreen(Screen):
email = ObjectProperty()
password = ObjectProperty()
def verify_user(self):
cur.execute('SELECT * from id WHERE email="%s" AND password="%s"' % (self.email.text, self.password.text))
if cur.fetchone() is not None:
HomeScreen.current = self.email.text
sm.current = 'Casa'
self.reset()
else:
self.invalidLogin()
self.reset()
def reset(self):
self.email.text = ""
self.password.text = ""
def invalidLogin(self):
pop = Popup(title='Invalid Login',
content=Label(text='Invalid username or password.'),
size_hint=(None, None), size=(400, 400),separator_color=(1.36, 0, .27, 1))
pop.open()
self.email.text = ""
self.password.text = ""
kv = Builder.load_file("main.kv")
sm = ScreenManagement()
screens = [LoginScreen(name="login"), SignUpScreen(name="signup"),HomeScreen(name="Casa"),SearchScreen(name="Search")]
for screen in screens:
sm.add_widget(screen)
sm.current = 'login'
con = sql.connect('userlog.db')
cur = con.cursor()
class MainApp(App):
def build(self):
return sm
if __name__ == "__main__":
MainApp().run()
主文件
HomeScreen>:
name: "Casa"
usr: usr
email: email
canvas.before:
Rectangle:
pos: self.pos
size: self.size
source: 'images/LightBackgroundReOr.png'
FloatLayout:
GridLayout:
pos_hint: {"top": 1, "left": 1}
size_hint: 1, .1
Image:
id: imageView
source: 'images/uaiLogoReOr.png'
size_hint: 0.25, 0.25
pos_hint: {'center_x':.5, 'y':.7}
Label:
id: usr
pos_hint:{"x": 0.1, "top":0.9}
size_hint:0.8, 0.2
text: "Olá "
Label:
id: email
pos_hint:{"x": 0.1, "top":0.9}
size_hint:0.8, 0.2
text: ""
...
解决方案
推荐阅读
- python - Python MKL_THREADING_LAYER=INTEL 与 libgomp.so.1 库不兼容
- typescript - Vue3 组件库 + Typescript + Rollup + Mocha - 带有 mount/shallowmount 的单元测试。有没有人做到过
- wordpress - WordPress 中带有 URL 编码字符的图像上传文件夹返回 404
- c - MPI 中的矩阵乘法无法收集
- php - 使用我的 Phpmailer 连接到 Webmail 服务器时遇到问题
- python - 如果我删除 conda 环境,它会自动删除所有包吗?
- r - R - 通过在相同前缀上匹配值同时截断发散后缀来处理 data.table 中的字符变量
- javascript - Firebase:Vue.js:无法将存储与数据库连接
- flutter - 带有子图表问题的扩展小部件
- javascript - 尝试根据悬停显示链接,但它不起作用(反应)