fix proxy
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user