MCPcopy Create free account
hub / github.com/TheSmallHanCat/flow2api / get_custom_token

Method get_custom_token

src/services/browser_captcha.py:2408–2467  ·  view source on GitHub ↗

Get a custom reCAPTCHA token using a temporary browser.

(
        self,
        website_url: str,
        website_key: str,
        action: str = "homepage",
        enterprise: bool = False,
    )

Source from the content-addressed store, hash-verified

2406 self.note_idle()
2407
2408 async def get_custom_token(
2409 self,
2410 website_url: str,
2411 website_key: str,
2412 action: str = "homepage",
2413 enterprise: bool = False,
2414 ) -> Optional[str]:
2415 """Get a custom reCAPTCHA token using a temporary browser."""
2416 async with self._semaphore:
2417 self._solve_inflight += 1
2418 max_retries = 3
2419
2420 try:
2421 for attempt in range(max_retries):
2422 playwright = None
2423 browser = None
2424 context = None
2425 try:
2426 start_ts = time.time()
2427 playwright, browser, context = await self._create_browser(manage_slot_pid=False)
2428 token = await self._execute_custom_captcha(
2429 context=context,
2430 website_url=website_url,
2431 website_key=website_key,
2432 action=action,
2433 enterprise=enterprise,
2434 )
2435
2436 if token:
2437 self._solve_count += 1
2438 debug_logger.log_info(
2439 f"[BrowserCaptcha] Token-{self.token_id} custom token acquired ({(time.time()-start_ts)*1000:.0f}ms)"
2440 )
2441 return token
2442
2443 self._error_count += 1
2444 debug_logger.log_warning(
2445 f"[BrowserCaptcha] Token-{self.token_id} custom token attempt {attempt+1}/{max_retries} failed"
2446 )
2447 except Exception as e:
2448 self._error_count += 1
2449 debug_logger.log_error(
2450 f"[BrowserCaptcha] Token-{self.token_id} custom browser error: {type(e).__name__}: {str(e)[:200]}"
2451 )
2452 finally:
2453 await self._close_browser(
2454 playwright,
2455 browser,
2456 context,
2457 browser_pid=self._extract_browser_pid(browser),
2458 clear_slot_pid=False,
2459 )
2460
2461 if attempt < max_retries - 1:
2462 await asyncio.sleep(1)
2463
2464 return None
2465 finally:

Callers 1

get_custom_tokenMethod · 0.45

Calls 9

_create_browserMethod · 0.95
_close_browserMethod · 0.95
_extract_browser_pidMethod · 0.95
note_idleMethod · 0.95
log_infoMethod · 0.80
log_warningMethod · 0.80
log_errorMethod · 0.80
sleepMethod · 0.80

Tested by

no test coverage detected