fix headless
This commit is contained in:
@@ -58,6 +58,7 @@ class BrowserService:
|
||||
settings.DEFAULT_MAX_READING
|
||||
)
|
||||
|
||||
for attempt in range(3):
|
||||
proxy = None
|
||||
use_socks5 = False
|
||||
|
||||
@@ -68,16 +69,13 @@ class BrowserService:
|
||||
|
||||
# Определяем конфигурацию
|
||||
if proxy and proxy.proxy_type in [ProxyType.SOCKS5, ProxyType.SOCKS4]:
|
||||
# SOCKS5 через локальный HTTP туннель
|
||||
proxy_config = await self.socks5_pool.get_proxy_config(proxy)
|
||||
use_socks5 = True
|
||||
logger.info(f"Using SOCKS5 tunnel for: {proxy.id}")
|
||||
elif proxy:
|
||||
# HTTP прокси напрямую
|
||||
proxy_config = proxy.proxy_config
|
||||
logger.info(f"Using HTTP proxy: {proxy.id}")
|
||||
else:
|
||||
# Прямое соединение
|
||||
proxy_config = None
|
||||
logger.info("Direct connection")
|
||||
|
||||
@@ -97,7 +95,7 @@ class BrowserService:
|
||||
)
|
||||
else:
|
||||
async with AsyncCamoufox(
|
||||
headless=False,
|
||||
headless=True,
|
||||
geoip=False,
|
||||
humanize=True,
|
||||
locale="ru-RU",
|
||||
@@ -115,16 +113,23 @@ class BrowserService:
|
||||
|
||||
return result
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Visit error: {e}", exc_info=True)
|
||||
|
||||
except ValueError as e:
|
||||
logger.warning(f"Visit attempt {attempt + 1} fingerprint error, retrying with new proxy: {e}")
|
||||
if proxy:
|
||||
await self.proxy_manager.release_proxy(proxy, success=False)
|
||||
if use_socks5:
|
||||
await self.socks5_pool.release(proxy)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Visit error: {e}", exc_info=True)
|
||||
if proxy:
|
||||
await self.proxy_manager.release_proxy(proxy, success=False)
|
||||
if use_socks5:
|
||||
await self.socks5_pool.release(proxy)
|
||||
return VisitResult(url=url, success=False, error=str(e))
|
||||
|
||||
return VisitResult(url=url, success=False, error="All attempts failed (geoip fingerprint error)")
|
||||
|
||||
async def _browse_page(
|
||||
self, browser, url: str, proxy_info: str, reading_time: int
|
||||
) -> VisitResult:
|
||||
@@ -271,7 +276,7 @@ class BrowserService:
|
||||
proxy_config = None
|
||||
|
||||
browser_kwargs = {
|
||||
"headless": False,
|
||||
"headless": True,
|
||||
"geoip": True,
|
||||
"humanize": True,
|
||||
"exclude_addons": [DefaultAddons.UBO],
|
||||
|
||||
Reference in New Issue
Block a user