Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions ceki_sdk/_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,14 +569,23 @@ async def _create_captcha_event(
"acceptance_deadline_at": int(acceptance_timeout),
"completion_deadline_at": int(completion_timeout),
}
async with httpx.AsyncClient() as http:
resp = await http.post(
f"{self._client.api_url}/api/agent/sessions/{self._match.event_id}/captcha-request",
headers={**self._api_headers(), "Content-Type": "application/json"},
json=body,
)
resp.raise_for_status()
result = resp.json()
url = f"{self._client.api_url}/api/agent/sessions/{self._match.event_id}/captcha-request"
backoff = [0.5, 1.0, 2.0, 4.0]
last_resp = None
for delay in [0.0] + backoff:
if delay:
await asyncio.sleep(delay)
async with httpx.AsyncClient() as http:
resp = await http.post(
url,
headers={**self._api_headers(), "Content-Type": "application/json"},
json=body,
)
last_resp = resp
if resp.status_code != 422 or "Session not active" not in (resp.text or ""):
break
last_resp.raise_for_status()
result = last_resp.json()
event_id = result.get("id")
if not event_id:
raise RuntimeError("captcha request did not return an id")
Expand Down