fix proxy

This commit is contained in:
Yuriy Yuriev
2026-05-22 01:22:56 +07:00
parent 2a6c1cd633
commit 2f18f4a5a1
3 changed files with 65 additions and 25 deletions
+16 -6
View File
@@ -188,16 +188,26 @@ class BrowserService:
else:
return VisitResult(url=url, success=False, error="No proxy available")
# Определяем тип ошибки: ошибка соединения (прокси сломан) vs ошибка загрузки (прокси ok)
is_proxy_dead = result.error and any(
k in result.error for k in ("502", "Bad Gateway", "SOCKS", "NS_ERROR_PROXY")
)
is_load_error = result.error and not is_proxy_dead and any(
k in result.error for k in ("Timeout", "ERR_", "NS_ERROR_", "Connection")
)
if proxy:
await self.proxy_manager.release_proxy(proxy, result.success)
# Таймаут/ошибка загрузки — прокси не виноват, освобождаем без штрафа
release_success = True if is_load_error else result.success
await self.proxy_manager.release_proxy(proxy, release_success)
if use_socks5:
await self.socks5_pool.release(proxy)
# Если таймаут или соединение не прошло — помечаем прокси как нерабочий и меняем
if not result.success and result.error and any(
k in result.error for k in ("Timeout", "ERR_", "Connection", "SOCKS", "NS_ERROR_", "502", "Bad Gateway")
):
logger.warning(f"Visit attempt {attempt + 1} bad proxy, retrying with new")
if is_proxy_dead:
logger.warning(f"Visit attempt {attempt + 1} proxy connection failed, retrying with new")
continue
elif is_load_error:
logger.warning(f"Visit attempt {attempt + 1} page load error (proxy ok), retrying")
continue
return result