增加网络默认超时时间
This commit is contained in:
@@ -90,6 +90,9 @@ class Config:
|
|||||||
CDN_ITEM_FILE = PROJECT_DIR + 'data/cdn.txt'
|
CDN_ITEM_FILE = PROJECT_DIR + 'data/cdn.txt'
|
||||||
CDN_ENABLED_AVAILABLE_ITEM_FILE = QUERY_DATA_DIR + 'available.json'
|
CDN_ENABLED_AVAILABLE_ITEM_FILE = QUERY_DATA_DIR + 'available.json'
|
||||||
|
|
||||||
|
# Default time out
|
||||||
|
TIME_OUT_OF_REQUEST = 5
|
||||||
|
|
||||||
envs = []
|
envs = []
|
||||||
retry_time = 5
|
retry_time = 5
|
||||||
last_modify_time = 0
|
last_modify_time = 0
|
||||||
|
|||||||
@@ -53,6 +53,9 @@ class Request(HTMLSession):
|
|||||||
|
|
||||||
def request(self, *args, **kwargs): # 拦截所有错误
|
def request(self, *args, **kwargs): # 拦截所有错误
|
||||||
try:
|
try:
|
||||||
|
if not 'timeout' in kwargs:
|
||||||
|
from py12306.config import Config
|
||||||
|
kwargs['timeout'] = Config().TIME_OUT_OF_REQUEST
|
||||||
response = super().request(*args, **kwargs)
|
response = super().request(*args, **kwargs)
|
||||||
return response
|
return response
|
||||||
except RequestException as e:
|
except RequestException as e:
|
||||||
|
|||||||
Reference in New Issue
Block a user