mirror of
https://github.com/nirvana-7777/script.service.ultimate.git
synced 2026-09-29 04:22:42 +02:00
magentaeu: more headers
This commit is contained in:
@@ -51,7 +51,10 @@ class HTTPManager:
|
||||
retry_strategy = Retry(
|
||||
total=self.config.max_retries,
|
||||
backoff_factor=self.config.retry_delay,
|
||||
status_forcelist=[429, 500, 502, 503, 504],
|
||||
# Only retry 429 (Rate limit) at the urllib3 level.
|
||||
# 500/503 should be handled by the provider's EPG manager
|
||||
# to prevent Akamai bot detection.
|
||||
status_forcelist=[429],
|
||||
allowed_methods=["HEAD", "GET", "OPTIONS", "POST", "PUT", "DELETE"],
|
||||
)
|
||||
|
||||
@@ -196,10 +199,11 @@ class HTTPManager:
|
||||
# Merge with any additional kwargs (caller overrides win)
|
||||
request_kwargs.update(kwargs)
|
||||
|
||||
# Inject Referer from last response URL if not already set by caller
|
||||
# Inject Referer from last response URL if not already set by caller.
|
||||
# NOTE: Auto-injecting Referer is disabled by default because WAFs (like Akamai)
|
||||
# flag API requests that have backend API URLs as the Referer.
|
||||
# Providers should explicitly set the Referer header in their own header factories if needed.
|
||||
headers = request_kwargs.setdefault("headers", {})
|
||||
if "Referer" not in headers and self._last_url:
|
||||
headers["Referer"] = self._last_url
|
||||
|
||||
# Inject Origin derived from target URL only when explicitly requested.
|
||||
# Origin injection is opt-in because some non-browser APIs reject
|
||||
|
||||
@@ -463,6 +463,7 @@ class MagentaEUEpgManager:
|
||||
|
||||
# Add retry logic
|
||||
max_retries = 3
|
||||
block_success = False
|
||||
for attempt in range(max_retries):
|
||||
try:
|
||||
response = self._http.get(
|
||||
@@ -473,6 +474,7 @@ class MagentaEUEpgManager:
|
||||
)
|
||||
response.raise_for_status()
|
||||
merged[url] = response.json()
|
||||
block_success = True
|
||||
break # Success, exit retry loop
|
||||
except Exception as exc:
|
||||
if attempt < max_retries - 1:
|
||||
@@ -489,6 +491,14 @@ class MagentaEUEpgManager:
|
||||
f"schedule fetch offset={hour_offset} failed after {max_retries} attempts: {exc}"
|
||||
)
|
||||
|
||||
# If the block failed after all retries, skip it and move to the next block
|
||||
if not block_success:
|
||||
logger.warning(
|
||||
f"[MagentaEUEpgManager/{self._country}] "
|
||||
f"Skipping block offset={hour_offset} due to server 500/503 errors."
|
||||
)
|
||||
continue
|
||||
|
||||
return merged
|
||||
|
||||
def _fetch_program_details(self, program_id: str) -> Dict[str, Any]:
|
||||
|
||||
Reference in New Issue
Block a user