This commit is contained in:
jinql
2025-09-07 21:23:42 +08:00
parent 3102ce8b8e
commit d78476e78a
9 changed files with 484 additions and 106 deletions

View File

@@ -14,6 +14,7 @@ import requests
import urllib3
from urllib3.exceptions import MaxRetryError, ReadTimeoutError, ConnectTimeoutError
import setting
from favicon_app.utils import header
from favicon_app.utils.filetype import helpers, filetype
@@ -32,10 +33,6 @@ requests_session.verify = False
DEFAULT_TIMEOUT = 10
DEFAULT_RETRIES = 2
# 时间常量
time_of_1_days = 1 * 24 * 60 * 60
time_of_7_days = 7 * time_of_1_days
# 存储失败的URL值为缓存过期时间戳
failed_urls: Dict[str, int] = dict()
@@ -111,7 +108,7 @@ class Favicon:
if self.domain:
self.domain_md5 = hashlib.md5(self.domain.encode("utf-8")).hexdigest()
except Exception as e:
failed_url_cache(self.domain, time_of_1_days)
failed_url_cache(self.domain, setting.time_of_1_days)
self.scheme = None
self.domain = None
logger.error('URL解析错误: %s, URL: %s', str(e), url)
@@ -290,7 +287,7 @@ class Favicon:
return req.content, ct_type
else:
failed_url_cache(domain, time_of_7_days)
failed_url_cache(domain, setting.time_of_7_days)
logger.error('请求失败: %d, URL: %s', req.status_code, url)
break
except (ConnectTimeoutError, ReadTimeoutError) as e:
@@ -304,7 +301,7 @@ class Favicon:
logger.error('重定向次数过多: %s, URL: %s', str(e), url)
break
except Exception as e:
failed_url_cache(domain, time_of_7_days)
failed_url_cache(domain, setting.time_of_7_days)
logger.error('请求异常: %s, URL: %s', str(e), url)
break
@@ -346,7 +343,7 @@ class Favicon:
return True
return False
except Exception as e:
failed_url_cache(domain, time_of_7_days)
failed_url_cache(domain, setting.time_of_7_days)
logger.error('解析域名出错: %s, 错误: %s', domain, str(e))
return False