From 00e28ba8311e6e5bf6f1cecb10ce8fb74474b349 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?X=C3=A9fir=20Destiny?= Date: Wed, 8 Jan 2020 19:34:45 +0100 Subject: [PATCH] Fix timeout crash --- connectors.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/connectors.py b/connectors.py index fadf5c4..13e702d 100644 --- a/connectors.py +++ b/connectors.py @@ -10,6 +10,7 @@ from urllib.parse import quote import requests from bs4 import BeautifulSoup +from requests import ReadTimeout from config import IS_DEBUG, CACHE_TIMEOUT from models import AnimeLink @@ -157,13 +158,19 @@ class Connector(ABC): else: headers = {} - if params is not None: - response = requests.post(url, params, timeout=10, headers=headers) - else: - response = requests.get(url, timeout=10, headers=headers) + try: + if params is not None: + response = requests.post(url, params, timeout=5, headers=headers) + else: + response = requests.get(url, timeout=5, headers=headers) - output = response.text - http_code = response.status_code + output = response.text + 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}