增加网络默认超时时间

This commit is contained in:
Jalin
2019-01-29 15:37:04 +08:00
parent e81a239609
commit 66ad9c9e5c
2 changed files with 6 additions and 0 deletions

View File

@@ -90,6 +90,9 @@ class Config:
CDN_ITEM_FILE = PROJECT_DIR + 'data/cdn.txt'
CDN_ENABLED_AVAILABLE_ITEM_FILE = QUERY_DATA_DIR + 'available.json'
# Default time out
TIME_OUT_OF_REQUEST = 5
envs = []
retry_time = 5
last_modify_time = 0

View File

@@ -53,6 +53,9 @@ class Request(HTMLSession):
def request(self, *args, **kwargs): # 拦截所有错误
try:
if not 'timeout' in kwargs:
from py12306.config import Config
kwargs['timeout'] = Config().TIME_OUT_OF_REQUEST
response = super().request(*args, **kwargs)
return response
except RequestException as e: