A small Python reCAPTCHA v2 solver that works without Selenium or a headless browser: it reads the form with requests, gets a token from the official CapMonster Cloud reCAPTCHA v2 solver Python SDK and submits the form over HTTP. Useful for lightweight scrapers and API-style integrations on sites you are allowed to automate.
- Downloads the page with a
requests.Sessionand a fixed desktop User-Agent. - Parses the form that contains the reCAPTCHA v2 widget: sitekey,
action, method and hidden fields. - Asks CapMonster Cloud for a token with
RecaptchaV2Request, sending the same User-Agent. - Posts the form back with
g-recaptcha-response, keeping cookies from the first request.
The default target is the public demo page lessons.zennolab.com.
- Python 3.9+
- A CapMonster Cloud API key (see Get an API key)
- No browser and no WebDriver
git clone https://github.com/CapMonsterCloud/python-requests-recaptcha-v2-solver.git
cd python-requests-recaptcha-v2-solver
pip install -r requirements.txt
export CAPMONSTER_API_KEY=your_key # Windows: set CAPMONSTER_API_KEY=your_key
python examples/solve_recaptcha_v2_requests.py
python examples/solve_recaptcha_v2_requests.py --url https://your-site.example/form --field email=me@example.comTests (offline, no API key):
pytest -q- The form is the contract.
parse_recaptcha_form()uses only the standardhtml.parser. It picks the<form>that actually contains the widget (pages often have a search form first), resolves a relativeactionagainst the final page URL after redirects and collects hidden inputs such as CSRF tokens. - Sitekey fallbacks. If there is no
data-sitekeyattribute, the parser looks for a 40-characterk=value in an embedded anchor URL. - Same session end to end. Cookies from the GET request and the
Refererheader go with the POST. Many backends reject a valid token if the session that loaded the form is not the one that submits it. - Payload instead of DOM.
build_payload()addsg-recaptcha-responseexactly as the browser widget would post it, so the server cannot tell the difference between the two flows.
- The token is a
g-recaptcha-responsestring. Send it in the form payload under that name. - reCAPTCHA v2 tokens are single-use and short-lived. Request a new token for every submission and submit right away.
- Pass the same page URL and sitekey that the browser used, otherwise the token can be rejected on validation.
| Symptom | Cause and fix |
|---|---|
ValueError: No reCAPTCHA v2 sitekey found |
The widget is injected by JavaScript after load. Find the sitekey in DevTools and use the browser examples, or call the site's API directly. |
| Submission returns the form again | A required field is missing. Add it with --field name=value or check the hidden inputs the page expects. |
HTTP 403 on the first GET |
The site blocks plain HTTP clients. Send the headers a browser sends or use a proxy you are allowed to use. |
| Token accepted in a browser but not here | The server binds the token to cookies or IP. Keep one Session and send the solve through the same proxy. |
[ERROR_KEY_DOES_NOT_EXIST] / [ERROR_ZERO_BALANCE] |
Wrong API key or empty balance. |
This example needs a CapMonster Cloud account and API key. Register and get the key on the reCAPTCHA v2 solver page. There you will also find pricing and the API description. New users can ask support for a $0.10 test balance after registering.
Use this example only on websites you own or have explicit permission to automate. Respect the website's terms of service and applicable laws. Never commit your API key.
- Python SDK: CapMonster Cloud Python SDK
- reCAPTCHA v2 solving with CapMonster Cloud: capmonster.cloud/en/recaptcha-v2
reCAPTCHA is a trademark of Google LLC. CapMonster Cloud is not affiliated with or endorsed by Google.