获取 reCAPTCHA Token(从共享浏览器池选择 slot) Args: project_id: 项目 ID action: reCAPTCHA action token_id: 业务 token id(仅用于读取 token 级打码代理) Returns: (token, browser_ref) 元组,browser_ref 包含 browser_id 与请求级 request_ref
(self, project_id: str, action: str = "IMAGE_GENERATION", token_id: int = None)
| 2809 | return None |
| 2810 | |
| 2811 | async def get_token(self, project_id: str, action: str = "IMAGE_GENERATION", token_id: int = None) -> tuple[Optional[str], Union[int, str]]: |
| 2812 | """获取 reCAPTCHA Token(从共享浏览器池选择 slot) |
| 2813 | |
| 2814 | Args: |
| 2815 | project_id: 项目 ID |
| 2816 | action: reCAPTCHA action |
| 2817 | token_id: 业务 token id(仅用于读取 token 级打码代理) |
| 2818 | |
| 2819 | Returns: |
| 2820 | (token, browser_ref) 元组,browser_ref 包含 browser_id 与请求级 request_ref |
| 2821 | """ |
| 2822 | # 检查服务是否可用 |
| 2823 | self._check_available() |
| 2824 | |
| 2825 | self._stats["req_total"] += 1 |
| 2826 | token_proxy_url = await self._resolve_token_proxy_url(token_id) |
| 2827 | |
| 2828 | token: Optional[str] = None |
| 2829 | request_ref: Optional[str] = None |
| 2830 | |
| 2831 | # 全局并发限制(如果已配置) |
| 2832 | if self._token_semaphore: |
| 2833 | async with self._token_semaphore: |
| 2834 | browser_id = await self._select_browser_id(project_id) |
| 2835 | try: |
| 2836 | browser = await self._get_or_create_browser(browser_id) |
| 2837 | token, request_ref = await browser.get_token( |
| 2838 | project_id, |
| 2839 | self.website_key, |
| 2840 | action, |
| 2841 | token_proxy_url=token_proxy_url, |
| 2842 | token_id=token_id, |
| 2843 | ) |
| 2844 | finally: |
| 2845 | await self._release_slot_reservation(browser_id) |
| 2846 | |
| 2847 | if token: |
| 2848 | self._stats["gen_ok"] += 1 |
| 2849 | else: |
| 2850 | self._stats["gen_fail"] += 1 |
| 2851 | |
| 2852 | self._log_stats() |
| 2853 | return token, self._compose_browser_ref(browser_id, request_ref) |
| 2854 | |
| 2855 | browser_id = await self._select_browser_id(project_id) |
| 2856 | try: |
| 2857 | browser = await self._get_or_create_browser(browser_id) |
| 2858 | token, request_ref = await browser.get_token( |
| 2859 | project_id, |
| 2860 | self.website_key, |
| 2861 | action, |
| 2862 | token_proxy_url=token_proxy_url, |
| 2863 | token_id=token_id, |
| 2864 | ) |
| 2865 | finally: |
| 2866 | await self._release_slot_reservation(browser_id) |
| 2867 | |
| 2868 | if token: |
nothing calls this directly
no test coverage detected