移除HTTP详情请求日志
This commit is contained in:
@@ -22,7 +22,6 @@ from core.geetest.common.network import (
|
||||
get_c_s,
|
||||
req_fullpage_validate,
|
||||
)
|
||||
from utils.http_logger import log_http
|
||||
|
||||
|
||||
class AccountLike(Protocol):
|
||||
@@ -246,14 +245,9 @@ class DouyuLogin:
|
||||
"""
|
||||
统一发送请求,附带分段超时和更明确的错误信息。
|
||||
代理连接失败时自动重试获取新的代理IP。
|
||||
所有请求详情会记录到 HTTP 详情日志。
|
||||
"""
|
||||
timeout = kwargs.pop('timeout', self.timeout)
|
||||
safe_url = self._safe_url(url)
|
||||
req_data = kwargs.get('data')
|
||||
req_body = req_data if req_data else kwargs.get('json')
|
||||
current_proxy = self._current_proxy_url
|
||||
tag = self.account.username if self.account else ""
|
||||
|
||||
for attempt in range(max_retries):
|
||||
self._ensure_not_stopped()
|
||||
@@ -266,30 +260,9 @@ class DouyuLogin:
|
||||
f"{method.upper()} {safe_url} -> {response.status_code} "
|
||||
f"({elapsed:.2f}s)"
|
||||
)
|
||||
# 记录请求/响应详情
|
||||
resp_body = response.text[:500] if response.text else ""
|
||||
log_http(
|
||||
category="douyu_login",
|
||||
method=method,
|
||||
url=safe_url,
|
||||
request_headers=dict(self.session.headers),
|
||||
request_body=req_body,
|
||||
status_code=response.status_code,
|
||||
response_headers=dict(response.headers),
|
||||
response_body=resp_body,
|
||||
duration=elapsed,
|
||||
proxy=current_proxy,
|
||||
tag=tag,
|
||||
)
|
||||
return response
|
||||
except requests.Timeout as exc:
|
||||
elapsed = time.monotonic() - started
|
||||
log_http(
|
||||
category="douyu_login", method=method, url=safe_url,
|
||||
request_headers=dict(self.session.headers), request_body=req_body,
|
||||
duration=elapsed, error=f"超时 timeout={timeout}: {exc}",
|
||||
proxy=current_proxy, tag=tag,
|
||||
)
|
||||
raise TimeoutError(
|
||||
f"{method.upper()} {safe_url} 超时,耗时 {elapsed:.1f}s,"
|
||||
f"timeout={timeout}"
|
||||
@@ -298,18 +271,10 @@ class DouyuLogin:
|
||||
elapsed = time.monotonic() - started
|
||||
err_str = str(exc)
|
||||
is_proxy_err = "proxy" in err_str.lower() or "Proxy" in type(exc).__name__
|
||||
log_http(
|
||||
category="douyu_login", method=method, url=safe_url,
|
||||
request_headers=dict(self.session.headers), request_body=req_body,
|
||||
duration=elapsed,
|
||||
error=f"{'代理' if is_proxy_err else ''}连接失败: {err_str[:300]}",
|
||||
proxy=current_proxy, tag=tag,
|
||||
)
|
||||
if is_proxy_err:
|
||||
logger.warning(f"代理连接失败,尝试 {attempt + 1}/{max_retries}: {exc}")
|
||||
if attempt < max_retries - 1:
|
||||
self._refresh_proxy()
|
||||
current_proxy = self._current_proxy_url
|
||||
self._sleep_interruptible(1)
|
||||
continue
|
||||
raise ConnectionError(
|
||||
@@ -325,12 +290,6 @@ class DouyuLogin:
|
||||
) from exc
|
||||
except requests.RequestException as exc:
|
||||
elapsed = time.monotonic() - started
|
||||
log_http(
|
||||
category="douyu_login", method=method, url=safe_url,
|
||||
request_headers=dict(self.session.headers), request_body=req_body,
|
||||
duration=elapsed, error=f"请求异常: {exc}",
|
||||
proxy=current_proxy, tag=tag,
|
||||
)
|
||||
raise ConnectionError(
|
||||
f"{method.upper()} {safe_url} 请求失败,耗时 {elapsed:.1f}s: {exc}"
|
||||
) from exc
|
||||
|
||||
Reference in New Issue
Block a user