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
This commit is contained in:
comet
2026-04-02 14:11:44 +08:00
committed by GitHub
parent 5d18293f1e
commit d37f98bdce
2 changed files with 6 additions and 4 deletions

View File

@@ -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()

View File

@@ -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}")