From d37f98bdcec838e1f893b62c342c3f9daad17bde Mon Sep 17 00:00:00 2001 From: comet Date: Thu, 2 Apr 2026 14:11:44 +0800 Subject: [PATCH] fix: avoid impersonation for captcha API JSON requests (#110) * fix: avoid impersonation for captcha API JSON requests * fix: avoid impersonation for captcha API JSON requests --- src/api/admin.py | 4 ++-- src/services/flow_client.py | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/api/admin.py b/src/api/admin.py index 3faf2c6..556ebd4 100644 --- a/src/api/admin.py +++ b/src/api/admin.py @@ -369,11 +369,12 @@ async def _solve_recaptcha_with_api_service( create_url = f"{base_url.rstrip('/')}/createTask" get_url = f"{base_url.rstrip('/')}/getTaskResult" + # Do not use curl_cffi impersonation for captcha API JSON endpoints: some ASGI servers + # (for example FastAPI/Uvicorn) may receive an empty body and return 422. async with AsyncSession() as session: create_resp = await session.post( create_url, json={"clientKey": client_key, "task": task}, - impersonate="chrome120", timeout=30 ) create_json = create_resp.json() @@ -387,7 +388,6 @@ async def _solve_recaptcha_with_api_service( poll_resp = await session.post( get_url, json={"clientKey": client_key, "taskId": task_id}, - impersonate="chrome120", timeout=30 ) poll_json = poll_resp.json() diff --git a/src/services/flow_client.py b/src/services/flow_client.py index 18b65c1..4b08868 100644 --- a/src/services/flow_client.py +++ b/src/services/flow_client.py @@ -2397,6 +2397,8 @@ class FlowClient: page_action = action try: + # Do not use curl_cffi impersonation for captcha API JSON endpoints: some ASGI + # servers (for example FastAPI/Uvicorn) may receive an empty body and return 422. async with AsyncSession() as session: create_url = f"{base_url}/createTask" create_data = { @@ -2409,7 +2411,7 @@ class FlowClient: } } - result = await session.post(create_url, json=create_data, impersonate="chrome110") + result = await session.post(create_url, json=create_data) result_json = result.json() task_id = result_json.get('taskId') @@ -2426,7 +2428,7 @@ class FlowClient: "clientKey": client_key, "taskId": task_id } - result = await session.post(get_url, json=get_data, impersonate="chrome110") + result = await session.post(get_url, json=get_data) result_json = result.json() debug_logger.log_info(f"[reCAPTCHA {method}] polling #{i+1}: {result_json}")