Fix timeout crash
This commit is contained in:
parent
d7cfb85f22
commit
00e28ba831
@ -10,6 +10,7 @@ from urllib.parse import quote
|
|||||||
|
|
||||||
import requests
|
import requests
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
from requests import ReadTimeout
|
||||||
|
|
||||||
from config import IS_DEBUG, CACHE_TIMEOUT
|
from config import IS_DEBUG, CACHE_TIMEOUT
|
||||||
from models import AnimeLink
|
from models import AnimeLink
|
||||||
@ -157,13 +158,19 @@ class Connector(ABC):
|
|||||||
else:
|
else:
|
||||||
headers = {}
|
headers = {}
|
||||||
|
|
||||||
if params is not None:
|
try:
|
||||||
response = requests.post(url, params, timeout=10, headers=headers)
|
if params is not None:
|
||||||
else:
|
response = requests.post(url, params, timeout=5, headers=headers)
|
||||||
response = requests.get(url, timeout=10, headers=headers)
|
else:
|
||||||
|
response = requests.get(url, timeout=5, headers=headers)
|
||||||
|
|
||||||
output = response.text
|
output = response.text
|
||||||
http_code = response.status_code
|
http_code = response.status_code
|
||||||
|
except ReadTimeout as e:
|
||||||
|
output = ''
|
||||||
|
http_code = 500
|
||||||
|
if IS_DEBUG:
|
||||||
|
print(e)
|
||||||
|
|
||||||
return {'http_code': http_code, 'output': output}
|
return {'http_code': http_code, 'output': output}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user