优化查询错误

This commit is contained in:
Jalin
2019-01-14 12:34:48 +08:00
parent 88ddc87f03
commit 26d0f5a1de
7 changed files with 44 additions and 11 deletions

View File

@@ -1,3 +1,5 @@
from requests.exceptions import *
from py12306.helpers.func import *
from requests_html import HTMLSession, HTMLResponse
@@ -43,3 +45,15 @@ class Request(HTMLSession):
return Dict(result)
except:
return Dict(default)
def request(self, *args, **kwargs): # 拦截所有错误
try:
return super().request(*args, **kwargs)
except RequestException as e:
if e.response:
response = e.response
else:
response = HTMLResponse(HTMLSession)
response.status_code = 500
expand_class(response, 'json', Request.json)
return response