mirror of
https://github.com/TheSmallHanCat/flow2api.git
synced 2026-06-06 06:39:35 +08:00
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:
@@ -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()
|
||||
|
||||
@@ -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}")
|
||||
|
||||
Reference in New Issue
Block a user