def Login_Cmd(self, event=None): global HEADERS global STUDENT_ID global PASSWORD self.headers = HEADERS ID = self.ID.get() passwd = self.PassWord.get() v_code = self.vcode.get() if v_code == "": try: v_code = myOCR.myOCR_start(self.photo) except : v_code = '' self.vcode.insert(0,v_code) try: logindata="operation=&usercode_text="+ID+"&userpwd_text="+passwd+"&checkcode_text="+v_code+"&submittype=%C8%B7+%C8%CF" conn=httplib.HTTPConnection("222.30.32.10",timeout=10) conn.request("POST","http://222.30.32.10/stdloginAction.do",logindata,self.headers) res=conn.getresponse() response=res.read() content=response.decode("gb2312") conn.close() except: self.Log.insert(1.0,"网络连接错误,无法连接到选课系统。请检查网络连接!\n") if ReLoadData(): self.Refresh() else: return global Login_S Login_S = False self.err_code="未知错误" if content.find("stdtop") != -1: Login_S = True header = self.headers STUDENT_ID=ID PASSWORD=passwd self.Log.insert(1.0,"登录成功!\n") get_v_code=True if Login_S == False and (content.find(unicode("请输入正确的验证码","utf8")) != -1): self.err_code="验证码错误!" if not self.Refresh_Cmd(): get_v_code=False else: get_v_code=True if Login_S == False and (content.find(u"用户不存在或密码错误") != -1): self.err_code="用户不存在或密码错误!" if Login_S == False and (content.find(u"忙") != -1 or content.find(u"负载") != -1): self.err_code="系统忙,请稍后再试!" if (Login_S != True): self.Log.insert(1.0,self.err_code+'\n') if not get_v_code: self.Log.insert(1.0,'验证码刷新失败!\n') return
def AutoLogin(self): global STUDENT_ID global PASSWORD global Login_S global PROCESSING global StopSignal if STUDENT_ID=='' or PASSWORD=='': err_code="无法验证用户名及密码,自动登录失败!\n" self.Log.insert(1.0,err_code) self.Log.update() return False count=0 while count<5: count+=1 self.Log.insert(1.0,'尝试重新登录...\n') if not ReLoadData(): continue else: self.ID.delete(0,END) self.ID.insert(0,STUDENT_ID) self.PassWord.delete(0,END) self.PassWord.insert(0,PASSWORD) if self.Refresh_Cmd(): pass else: self.photo=PIL.Image.open("ValidateCode.jpg") self.im = PIL.ImageTk.PhotoImage(self.photo) self.V_Pic= Label(self.top,image = self.im) self.V_Pic.place(relx=0.05, rely=0.203, relwidth=0.327, relheight=0.053) self.vcode.delete(0,END) self.vcode.insert(0,myOCR.myOCR_start(self.photo)) self.Login_Cmd() if not Login_S: err_code='重新登录失败...3秒后重试\n' self.Log.insert(1.0,err_code) self.Log.update() for i in range(12): time.sleep(0.25) self.Log.update() if (not PROCESSING) and StopSignal: StopSignal=False return False else: self.Log.insert(1.0,"登录成功。继续刷课。\n") return True
def Login(): global HEADERS global STUDENT_ID global PASSWORD global LoginStatus global ValidateCode try: v_code=myOCR.myOCR_start(ValidateCode) except: return False try: logindata="operation=&usercode_text="+STUDENT_ID+"&userpwd_text="+PASSWORD+"&checkcode_text="+v_code+"&submittype=%C8%B7+%C8%CF" conn=httplib.HTTPConnection("222.30.32.10",timeout=20) conn.request("POST","http://222.30.32.10/stdloginAction.do",logindata,HEADERS) res=conn.getresponse() response=res.read() content=response.decode("gb2312") conn.close() except: print "网络连接错误,无法连接到选课系统。请检查网络连接!" return False if content.find("stdtop") != -1: LoginStatus = True #print "登录成功!" err_code = "未知错误!" if LoginStatus == False and (content.find(unicode("请输入正确的验证码","utf8")) != -1): err_code="验证码错误!" while not INIT(): continue return Login() if LoginStatus == False and (content.find(u"用户不存在或密码错误") != -1): err_code="用户不存在或密码错误!" if LoginStatus == False and (content.find(u"忙") != -1 or content.find(u"负载") != -1): err_code="系统忙,请稍后再试!" if (LoginStatus != True): print err_code return LoginStatus