From eb8d1f5a977aa8419e7f63ebf5a81a27e0c6587d Mon Sep 17 00:00:00 2001 From: a2r0n Date: Thu, 17 Jan 2019 14:41:59 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0status.json=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E6=97=B6=E7=9A=84=E5=AE=B9=E9=94=99=E5=A4=84?= =?UTF-8?q?=E7=90=86.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- py12306/log/query_log.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/py12306/log/query_log.py b/py12306/log/query_log.py index ef13141..9860d83 100644 --- a/py12306/log/query_log.py +++ b/py12306/log/query_log.py @@ -1,3 +1,4 @@ +# -*- coding:utf-8 -*- import datetime import json import sys @@ -57,8 +58,12 @@ class QueryLog(BaseLog): if not Config.is_cluster_enabled() and path.exists(self.data_path): with open(self.data_path, encoding='utf-8') as f: result = f.read() - if result: + try: result = json.loads(result) + except json.JSONDecodeError as e: + self.add_quick_log('加载status.json失败, 文件内容为: {}.'.format(repr(result))) + self.flush() + result = {} if Config.is_cluster_enabled(): result = self.get_data_from_cluster()