问题遇到的现象和发生背景
pycharm 运行爬虫程序,可以连接到数据库,注册用户但是登录时报错
问题相关代码,请勿粘贴截图
usernames = self.username.GetValue()
password = self.password.GetValue()
if usernames == "" and password == "":
wx.MessageBox('用户名密码不能为空', caption="错误提示")
return
try:
sql = "select * from users where username= %s"
cur.execute(sql, [usernames])
conn.commit()
except:
wx.MessageBox('系统错误', caption="错误提示")
user = cur.fetchone()
if user == None:
wx.MessageBox('用户不存在', caption="错误提示")
self.username.Clear()
self.password.Clear()
return
if usernames == user[0] and password == user[1]:
wx.MessageBox("登陆成功", caption="登陆成功")
spiderClient = KuroNeko_Spider_GUI.SpiderClient(None)
self.Show(False)
spiderClient.Show(True)
else:
wx.MessageBox('用户名或者密码错误', caption="错误提示")
self.username.Clear()
self.password.Clear()
return
运行结果及报错内容
Traceback (most recent call last):
File "D:\PythonProject\pythonProject\Sprider_movie\Login_to_Spider.py", line 113, in loginFunc
if usernames == user[0] and password == user[1]:
KeyError: 0