Fetch Tencent captcha challenge metadata and image bytes.
| 44 | randstr: str |
| 45 | ret: Any |
| 46 | error_code: str |
| 47 | error_message: str |
| 48 | sess: str |
| 49 | raw: dict[str, Any] |
| 50 | |
| 51 | |
| 52 | class TencentCaptchaClient: |
| 53 | """Fetch Tencent captcha challenge metadata and image bytes.""" |
| 54 | |
| 55 | def __init__( |
| 56 | self, |
| 57 | http_client: FingerprintHttpClient | None = None, |
| 58 | settings: Settings | None = None, |
| 59 | ) -> None: |
| 60 | self.settings = settings or get_settings() |
| 61 | self.http_client = http_client or FingerprintHttpClient(self.settings) |
| 62 | |
| 63 | def prehandle(self, account: AccountRecord) -> CaptchaChallenge: |
| 64 | callback = f"_aq_{int(time.time() * 1000)}" |
| 65 | user_agent = resolve_user_agent(account.user_agent, account.browser_impersonate) |
| 66 | response_text = self.http_client.request_text( |
| 67 | "GET", |
| 68 | f"{self.settings.tencent_captcha_domain}/cap_union_prehandle", |
| 69 | headers={ |
| 70 | "Accept": "*/*", |
| 71 | "Referer": self.settings.tencent_captcha_entry_url, |
| 72 | }, |
| 73 | params={ |
| 74 | "aid": self.settings.tencent_captcha_aid, |
| 75 | "protocol": "https", |
| 76 | "accver": "1", |
| 77 | "showtype": "popup", |
| 78 | "ua": base64.b64encode(user_agent.encode("utf-8")).decode("ascii"), |
| 79 | "noheader": "0", |
| 80 | "fb": "1", |
| 81 | "aged": "0", |
| 82 | "enableAged": "0", |
| 83 | "enableDarkMode": "0", |
| 84 | "grayscale": "1", |
| 85 | "clientype": "2", |
| 86 | "lang": "zh-cn", |
| 87 | "entry_url": self.settings.tencent_captcha_entry_url, |
| 88 | "elder_captcha": "0", |
| 89 | "js": "", |
| 90 | "login_appid": "", |
| 91 | "wb": "1", |
| 92 | "subsid": "1", |
| 93 | "callback": callback, |
| 94 | "sess": "", |
| 95 | }, |
| 96 | proxy_url=account.proxy_url or None, |
| 97 | user_agent=user_agent, |
| 98 | browser_impersonate=account.browser_impersonate or None, |
| 99 | ) |
| 100 | payload = self._parse_jsonp(response_text) |
| 101 | image_path = str( |
| 102 | (((payload.get("data") or {}).get("dyn_show_info") or {}).get("bg_elem_cfg") or {}).get("img_url") |
| 103 | or "" |
no outgoing calls
no test coverage detected