Captcha
Helpers for handling Instagram captcha challenges. Register a custom handler
with set_captcha_handler() that receives the challenge details and returns
the solved token.
| Method | Return | Description |
|---|---|---|
| set_captcha_handler(handler) | None | Register a callable that solves captcha challenges |
| captcha_resolve(**challenge_details) | str | Resolve a captcha using the registered handler |
Example:
from aiograpi import Client
def my_captcha_handler(details: dict) -> str:
# details contains: site_key, page_url, challenge_type, raw_challenge_json
# Forward to your favorite captcha solver and return the token
return solve_recaptcha(
site_key=details["site_key"],
page_url=details["page_url"],
)
cl = Client()
cl.set_captcha_handler(my_captcha_handler)
await cl.login(USERNAME, PASSWORD)
Source code in aiograpi/mixins/captcha.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
captcha_resolve(**challenge_details)
Resolve a captcha challenge using the registered handler.
Parameters
**challenge_details: Dict A dictionary containing details of the captcha challenge, such as site_key, challenge_type, raw_challenge_json, page_url.
Returns
str The solved captcha token (e.g., g-recaptcha-response).
Raises
CaptchaChallengeRequired If no handler is configured, or if the handler fails to return a token, or if the handler itself raises an unhandled exception. ClientError For unexpected errors during the process.
Source code in aiograpi/mixins/captcha.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
set_captcha_handler(handler)
Set a custom handler function for solving captcha challenges.
Parameters
handler: Callable[[Dict], str], optional A function that takes a dictionary of challenge details (e.g., site_key, page_url, raw_challenge_json) and returns the solved captcha token as a string. If None, clears the existing handler.
Source code in aiograpi/mixins/captcha.py
15 16 17 18 19 20 21 22 23 24 25 26 27 | |