Skip to content

Commit

Permalink
修改查询接口的异常检查
Browse files Browse the repository at this point in the history
  • Loading branch information
versionzhang committed Jan 23, 2019
1 parent 400f6aa commit 4a77b42
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions python12306/logic/query/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,15 @@ def run_query(self):
r'purpose_codes': find_by_name("ticket", Config.basic_config.ticket_type).sys_code
}
json_response = send_requests(LOGIN_SESSION, QUERY_URL_MAPPING, params=params)
if not isinstance(json_response, (list, dict)):
if not isinstance(json_response, dict):
return []
try:
if "data" in json_response and "result" in json_response['data']:
return [TrainDetail(v.split('|')) for v in json_response['data']['result']] or []
else:
return []
except KeyError:
return []
return [TrainDetail(v.split('|')) for v in json_response['data']['result']] or []

@staticmethod
def pretty_output(t):
Expand Down

0 comments on commit 4a77b42

Please sign in to comment.