移除HTTP详情请求日志

This commit is contained in:
yml2213
2026-06-24 09:29:47 +08:00
parent 7bb50a9bbf
commit d87aa7c1e6
10 changed files with 2 additions and 692 deletions
-29
View File
@@ -2,7 +2,6 @@
from concurrent.futures import ThreadPoolExecutor, as_completed
from typing import Optional
import time as _time
import requests
from loguru import logger
@@ -19,12 +18,9 @@ def verify_proxy_url(proxy_url: str, timeout: tuple = (5, 8)) -> tuple[bool, str
Returns:
(是否可用, 消息)
"""
from utils.http_logger import log_http
proxies = {'http': proxy_url, 'https': proxy_url}
# ── 第1关:斗鱼主站 ──
started = _time.monotonic()
try:
response = requests.get(
'https://www.douyu.com',
@@ -32,15 +28,8 @@ def verify_proxy_url(proxy_url: str, timeout: tuple = (5, 8)) -> tuple[bool, str
timeout=timeout,
headers={'User-Agent': 'Mozilla/5.0'},
)
elapsed = _time.monotonic() - started
response.raise_for_status()
log_http(
category="proxy_verify", method="GET", url="https://www.douyu.com",
status_code=response.status_code, response_body=f"斗鱼主站可达: {proxy_url}",
duration=elapsed, proxy=proxy_url, tag="proxy_verify",
)
except Exception as exc:
elapsed = _time.monotonic() - started
err_msg = str(exc)
if 'Tunnel connection failed' in err_msg or '503' in err_msg:
detail = '代理拒绝连接(白名单可能未生效)'
@@ -49,15 +38,9 @@ def verify_proxy_url(proxy_url: str, timeout: tuple = (5, 8)) -> tuple[bool, str
else:
detail = type(exc).__name__
logger.debug(f"代理验证失败 [{proxy_url}]: 斗鱼主站不可达: {detail}")
log_http(
category="proxy_verify", method="GET", url="https://www.douyu.com",
duration=elapsed, error=f"[{proxy_url}] {detail}: {err_msg[:200]}",
proxy=proxy_url, tag="proxy_verify",
)
return False, detail
# ── 第2关:极验接口 ──
started = _time.monotonic()
try:
response = requests.get(
'https://api.geetest.com',
@@ -67,26 +50,14 @@ def verify_proxy_url(proxy_url: str, timeout: tuple = (5, 8)) -> tuple[bool, str
# geetest 首页可能返回 4xx,只要能连上就算通
allow_redirects=True,
)
elapsed = _time.monotonic() - started
log_http(
category="proxy_verify", method="GET", url="https://api.geetest.com",
status_code=response.status_code, response_body=f"代理可用: {proxy_url}",
duration=elapsed, proxy=proxy_url, tag="proxy_verify",
)
return True, '代理可用 → 斗鱼+极验'
except Exception as exc:
elapsed = _time.monotonic() - started
err_msg = str(exc)
if 'timed out' in err_msg.lower():
detail = '极验接口超时'
else:
detail = f'极验不可达: {type(exc).__name__}'
logger.debug(f"代理验证失败 [{proxy_url}]: 斗鱼可达但{detail}")
log_http(
category="proxy_verify", method="GET", url="https://api.geetest.com",
duration=elapsed, error=f"[{proxy_url}] {detail}: {err_msg[:200]}",
proxy=proxy_url, tag="proxy_verify",
)
return False, detail