def write_error(self, status_code, **kwargs): if 'exc_info' in kwargs: # 参数缺失异常 if isinstance(kwargs['exc_info'][1], RequestArgumentError): self.write( json_result(kwargs['exc_info'][1].code, kwargs['exc_info'][1].msg)) return if status_code == 400: self.write(json_result(400, '缺少参数')) return
def write_error(self, status_code, **kwargs): if 'exc_info' in kwargs: # 参数缺失异常 if isinstance(kwargs['exc_info'][1],RequestArgumentError): self.write(json_result(kwargs['exc_info'][1].code,kwargs['exc_info'][1].msg)) return if status_code==400: self.write(json_result(400,'缺少参数')) return if not config.DEBUG: self.redirect("/static/500.html")
def write_error(self, status_code, **kwargs): if 'exc_info' in kwargs: # 参数缺失异常 if isinstance(kwargs['exc_info'][1], RequestArgumentError): self.write( json_result(kwargs['exc_info'][1].code, kwargs['exc_info'][1].msg)) return if status_code == 400: self.write(json_result(400, '缺少参数')) return if not config.DEBUG: self.redirect("/static/500.html")
def post(self, *args, **kwargs): post_data = get_cleaned_post_data(self, ['username', 'password']) #try: # post_data=get_cleaned_post_data(self,['username','password']) #except RequestArgumentError as e: # self.write(json_result(e.code,e.msg)) # return user = User.auth(post_data['username'], post_data['password']) if user: self.set_secure_cookie('uuid', user.username) result = json_result(0, 'login success!') self.redirect('/') else: result = json_result(-1, 'login failed!') self.redirect('/login')
def post(self, *args, **kwargs): post_data=get_cleaned_post_data(self,['username','password']) #try: # post_data=get_cleaned_post_data(self,['username','password']) #except RequestArgumentError as e: # self.write(json_result(e.code,e.msg)) # return user=User.auth(post_data['username'],post_data['password']) if user: self.set_secure_cookie('uuid',user.username) result=json_result(0,'login success!') self.redirect('/') else: result=json_result(-1,'login failed!') self.redirect('/login')
def get_login_cookie(self, user, captcha): # 验证码的cookie cookies = {'ASP.NET_SessionId': self.get_cookie('ASP.NET_SessionId')} passwd_encrpyt, captcha_encrpt = get_encrypt_code( user.username, user.passwd, captcha) data = { '__VIEWSTATE': self.get_cookie('ViewState'), 'pcInfo': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:47.0) Gecko/20100101 Firefox/47.0Intel Mac OS X 10.115.0 (Macintosh) SN:NULL', 'txt_asmcdefsddsd': user.username, # 密码密文 'dsdsdsdsdxcxdfgfg': passwd_encrpyt, # 验证码 'fgfggfdgtyuuyyuuckjg': captcha_encrpt, 'Sel_Type': 'STU', 'typeName': '学生' } response = requests.post('http://bkjw.sxu.edu.cn/_data/login.aspx', data=data, cookies=cookies, headers={ 'Host': 'bkjw.sxu.edu.cn', 'Referer': 'http://bkjw.sxu.edu.cn/_data/login.aspx' }, proxies={'http': 'http://127.0.0.1:8080'}) if '权限' not in response.text: self.write(json_result(1, '验证码失败')) return 1 return 0
def get_login_cookie(self, user): data = { 'Login.Token1': user.username, 'Login.Token2': user.passwd, } response = requests.post( 'http://myportal.sxu.edu.cn/userPasswordValidate.portal', data=data, headers={ 'Host': 'myportal.sxu.edu.cn', 'Content-Type': 'application/x-www-form-urlencoded' }, #proxies = {'http': 'http://127.0.0.1:8080'} ) if 'handleLoginSuccessed' not in response.text: self.write(json_result(1, '用户名密码验证失败')) return iPlanetDirectoryPro = response.cookies.get('iPlanetDirectoryPro') response = requests.get( 'http://stuach.sxu.edu.cn/student/caslogin.asp', allow_redirects=False, headers={ 'Host': 'stuach.sxu.edu.cn', 'User-Agent': '' }, cookies={'iPlanetDirectoryPro': iPlanetDirectoryPro}, #proxies = {'http': 'http://127.0.0.1:8080'} ) return response.cookies.get('ASPSESSIONIDACRRADAD')
def post_old(self, *args, **kwargs): post_data = get_cleaned_post_data(self, ['stuid', 'passwd', 'stutype']) #stuid = '2012241004' stuid = post_data['stuid'] #passwd = 'qwaszx' passwd = post_data['passwd'] stutype = post_data['stutype'] openid = get_cleaned_query_data(self, ['openid'])['openid'] data = { 'Login.Token1': stuid, 'Login.Token2': passwd, } response = requests.post( 'http://myportal.sxu.edu.cn/userPasswordValidate.portal', data=data, headers={ 'Host': 'myportal.sxu.edu.cn', 'Content-Type': 'application/x-www-form-urlencoded' }, #proxies = {'http': 'http://127.0.0.1:8080'} ) if 'handleLoginSuccessed' not in response.text: self.write(json_result(1, '用户名密码验证失败')) return iPlanetDirectoryPro = response.cookies.get('iPlanetDirectoryPro') response = requests.get( 'http://stuach.sxu.edu.cn/student/caslogin.asp', allow_redirects=False, headers={ 'Host': 'stuach.sxu.edu.cn', 'User-Agent': '' }, cookies={'iPlanetDirectoryPro': iPlanetDirectoryPro}, #proxies = {'http': 'http://127.0.0.1:8080'} ) ASPSESSIONIDACRRADAD = response.cookies.get('ASPSESSIONIDACRRADAD') response = requests.get( 'http://stuach.sxu.edu.cn/student/studentinfo.asp', headers={ 'Host': 'stuach.sxu.edu.cn', 'User-Agent': '' }, cookies={'ASPSESSIONIDACRRADAD': ASPSESSIONIDACRRADAD}, #proxies = {'http': 'http://127.0.0.1:8080'} ) stuname, stumajor = find_stu_info_old( response.content.decode('gb2312', 'ignore')) temp_user = User.get_by_openid(openid) if temp_user: temp_user.openid = temp_user.openid + '_d' temp_user.save() User.new(stuid, stuname, stumajor, passwd, stutype, openid, 'test') self.write( json_result(0, { 'stuid': stuid, 'stuname': stuname, 'stumajor': stumajor })) return
def get_myscore(self, user): # 登陆成功的cookie cookies = {'ASP.NET_SessionId': self.get_cookie('ASP.NET_SessionId')} response = requests.post( 'http://bkjw.sxu.edu.cn/xscj/Stu_MyScore_rpt.aspx', data={ 'SJ': 1, 'SelXNXQ': 0, 'zfx_flag': 0, 'zxf': 0, 'btn_search': '检索' }, cookies=cookies, headers={ 'Host': 'bkjw.sxu.edu.cn', 'Referer': 'http://bkjw.sxu.edu.cn/xscj/Stu_MyScore.aspx' }, proxies={'http': 'http://127.0.0.1:8080'}) stupoint = find_point(response.text) response = requests.get( 'http://bkjw.sxu.edu.cn/xscj/Stu_MyScore_Drawimg.aspx?x=1&h=2&w=739&xnxq=20150&xn=2015&xq=0&rpt=0&rad=2&zfx=0', cookies=cookies, headers={ 'Host': 'bkjw.sxu.edu.cn', 'Referer': 'http://bkjw.sxu.edu.cn/xscj/Stu_MyScore_rpt.aspx', 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36', 'Accept': 'image/webp,image/*,*/*;q=0.8' }, proxies={'http': 'http://127.0.0.1:8080'}) score_base64_img_semester_1 = ( "data:" + response.headers['Content-Type'] + ";" + "base64," + str(base64.b64encode(response.content).decode("utf-8", "ignore"))) response = requests.get( 'http://bkjw.sxu.edu.cn/xscj/Stu_MyScore_Drawimg.aspx?x=1&h=2&w=708&xnxq=20151&xn=2015&xq=1&rpt=0&rad=2&zfx=0', cookies=cookies, headers={ 'Host': 'bkjw.sxu.edu.cn', 'Referer': 'http://bkjw.sxu.edu.cn/xscj/Stu_MyScore_rpt.aspx', 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36', 'Accept': 'image/webp,image/*,*/*;q=0.8' }, #proxies = {'http': 'http://127.0.0.1:8080'} ) score_base64_img_semester_2 = ( "data:" + response.headers['Content-Type'] + ";" + "base64," + str(base64.b64encode(response.content).decode("utf-8", "ignore"))) self.write( json_result( 0, { 'stuname': user.nickname, 'stuid': user.username, 'stupoint': stupoint, 'stumajor': user.major, 'score_base64_img_semester_1': score_base64_img_semester_1, 'score_base64_img_semester_2': score_base64_img_semester_2 })) return 0
def post_new(self, *args, **kwargs): #stuid = self.get_body_argument('stuid') #passwd = self.get_body_argument('passwd') post_data = get_cleaned_post_data( self, ['stuid', 'passwd', 'captcha', 'stutype']) captcha = post_data['captcha'] #stuid = '201502401037' stuid = post_data['stuid'] #passwd = '622307' passwd = post_data['passwd'] stutype = post_data['stutype'] openid = get_cleaned_query_data(self, ['openid'])['openid'] passwd_encrpyt, captcha_encrpt = get_encrypt_code( stuid, passwd, captcha) cookies = {'ASP.NET_SessionId': self.get_cookie('ASP.NET_SessionId')} data = { '__VIEWSTATE': self.get_cookie('ViewState'), 'pcInfo': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:47.0) Gecko/20100101 Firefox/47.0Intel Mac OS X 10.115.0 (Macintosh) SN:NULL', 'txt_asmcdefsddsd': stuid, # 密码密文 'dsdsdsdsdxcxdfgfg': passwd_encrpyt, # 验证码 'fgfggfdgtyuuyyuuckjg': captcha_encrpt, 'Sel_Type': 'STU', 'typeName': '学生' } response = requests.post( 'http://bkjw.sxu.edu.cn/_data/login.aspx', data=data, cookies=cookies, headers={ 'Host': 'bkjw.sxu.edu.cn', 'Referer': 'http://bkjw.sxu.edu.cn/_data/login.aspx' }, #proxies = {'http': 'http://127.0.0.1:8080'} ) if '帐号或密码不正确' in response.text: self.write(json_result(1, '账号或密码不正确')) return elif '验证码错误' in response.text: self.write(json_result(1, '验证码错误')) return elif '权限' not in response.text: self.write(json_result(1, '未知错误')) return response = requests.get( 'http://bkjw.sxu.edu.cn/xsxj/Stu_MyInfo_RPT.aspx', cookies=cookies, headers={ 'Host': 'bkjw.sxu.edu.cn', 'Referer': 'http://bkjw.sxu.edu.cn/xsxj/Stu_MyInfo.aspx' }, #proxies = {'http': 'http://127.0.0.1:8080'} ) stuid, stuname, stumajor = get_stu_info(response.text) temp_user = User.get_by_openid(openid) if temp_user: temp_user.openid = temp_user.openid + '_d' temp_user.save() User.new(stuid, stuname, stumajor, passwd, stutype, openid, 'test') self.write( json_result(0, { 'stuid': stuid, 'stuname': stuname, 'stumajor': stumajor })) return