Skip to content

Commit

Permalink
fix:修复登陆失败提示网络环境的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
dcp committed Dec 2, 2020
1 parent 9fb698f commit d38e12b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 22 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# UCAS Helper
![python version](https://img.shields.io/badge/python-3.5%2B-blue)
![demo version](https://img.shields.io/badge/version-2.0.4-brightgreen)
![demo version](https://img.shields.io/badge/version-2.0.5-brightgreen)
![license](https://img.shields.io/badge/license-GNU%20v3-yellowgreen)
```angular2
*********************************************************************************
Expand All @@ -10,7 +10,7 @@
** # # # ####### # # # # # # # # # **
** ### ### ## ## ### # # ### ##### # ### # # **
** copyright@GentleCP **
** version: 2.0.4 **
** version: 2.0.5 **
** github: https://github.com/GentleCP/UCASHelper **
** 1:course sources download **
** 2:wifi login **
Expand Down Expand Up @@ -80,6 +80,7 @@
![](img/1.7.0.png)

# 2. 更新日志
- [2.0.5] 修复登陆接口请求失败的问题,建议使用最新的更新方式,见[5.5 更新项目](#55-更新项目)
- [2.0.4] 修复评估教师失败的bug
- [2.0.3] 修复了部分课程因html解析不当导致的课程资源无法下载的情况,本次更新需要用到新的依赖包`lxml=4.5.2`
已安装老版本的请重新执行`pip install -r requirements.txt`
Expand Down
46 changes: 27 additions & 19 deletions core/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import requests
import settings
import json
import warnings
warnings.filterwarnings('ignore')

from core.exception import HttpError

Expand All @@ -28,15 +30,20 @@ def __init__(self, user_info, urls):
self._S = requests.session()
self._user_info = user_info
self._urls = urls

self.headers = {
'Connection': 'keep-alive',
'sec-ch-ua': '"Google Chrome";v="87", "\\"Not;A\\\\Brand";v="99", "Chromium";v="87"',
'Accept': '*/*',
'Origin': 'http://jwxk.ucas.ac.cn',
'X-Requested-With': 'XMLHttpRequest',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36',
'sec-ch-ua-mobile': '?0',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.67 Safari/537.36',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'Referer': 'http://jwxk.ucas.ac.cn/evaluate/evaluateCourse/165683',
'Accept-Encoding': 'gzip, deflate',
'Origin': 'https://onestop.ucas.ac.cn',
'Sec-Fetch-Site': 'same-origin',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Dest': 'empty',
'Referer': 'https://onestop.ucas.ac.cn/',
'Accept-Language': 'zh-CN,zh;q=0.9',
}

Expand All @@ -50,31 +57,32 @@ def __keep_session(self):
self._S.get(course_select_url,headers=self.headers)

def login(self):
self._S.get(url="https://onestop.ucas.ac.cn/", headers=self.headers, verify=False) # 获取identity
res = None
try:
res = self._S.post(url=self._urls["login_url"]['http'], data=self._user_info, headers=self.headers, timeout=10)

res = self._S.post(url=self._urls["login_url"]['https'], data=self._user_info, headers=self.headers, timeout=10)
except (requests.exceptions.ConnectionError,
requests.exceptions.ConnectTimeout,
requests.exceptions.ReadTimeout):
self._logger.error("网络连接失败,请确认你的网络环境后重试!")
exit(400)

else:
if res.status_code == 200:
json_res = res.json()
else:
res = self._S.post(url=self._urls["login_url"]['https'], data=self._user_info, headers=self.headers, timeout=5)
json_res = res.json()
try:
json_res = res.json()
except json.decoder.JSONDecodeError:
self._logger.info("站点https证书失效,更换到http请求")
res = self._S.post(url=self._urls["login_url"]['http'], data=self._user_info, headers=self.headers,timeout=5)
json_res = res.json()

if json_res["f"]:
self._S.get(res.json()["msg"], headers=self.headers)
self._logger.info("sep登录成功!")
self.__keep_session()
if json_res["f"]:
self._S.get(res.json()["msg"], headers=self.headers)
self._logger.info("sep登录成功!")
self.__keep_session()


else:
self._logger.error("sep登录失败,请检查settings下的USER_INFO是否正确!")
exit(401)
else:
self._logger.error("sep登录失败,请检查settings下的USER_INFO是否正确!")
exit(401)


if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion core/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
** # # # ####### # # # # # # # # # **
** ### ### ## ## ### # # ### ##### # ### # # **
** copyright@GentleCP **
** version: 2.0.4 **
** version: 2.0.5 **
** github: https://github.com/GentleCP/UCASHelper **
** 1:course sources download **
** 2:wifi login **
Expand Down

0 comments on commit d38e12b

Please sign in to comment.