reCAPTCHA
How to solve reCAPTCHA v2 in Python
This guide builds a small Python client on the requests library that turns a reCAPTCHA v2 checkbox into a token your script can submit. Each task costs $0.56 per 1,000 and usually returns under 9 seconds.
What you need before writing code
You need three things: Python 3.9 or newer with the requests package, an API key from your GateSolver account, and the address of the page that shows the checkbox. Install the library with pip install requests if it is not already in your environment.
The flow itself is short. Your script sends the page URL and the widget's site key to /createTask, receives a task id, asks /getTaskResult about that id every three seconds, and finally gets a g-recaptcha-response token. That token is what the site's server checks with Google, so it is the only part of the checkbox your script has to supply.
Read the site key from the page
The site key is a public string, about 40 characters long and usually starting with 6L. Most pages render the widget from a div with a data-sitekey attribute, so a quick HTML parse finds it. If the widget is created by JavaScript instead, the guide on how to find the reCAPTCHA site key covers the iframe and network tab methods.
import re
import requests
def read_site_key(page_url: str) -> str | None:
html = requests.get(page_url, timeout=20).text
hit = re.search(r'data-sitekey="([\w-]{30,})"', html)
return hit.group(1) if hit else None
A regular expression is fine for a single attribute. If you already parse the page with Beautiful Soup, soup.select_one("[data-sitekey]")["data-sitekey"] does the same job with less guesswork about quoting.
Create the task and poll for the answer
The client below keeps the two API calls in separate functions so each one has a single reason to fail. Errors come back as errorId: 1 with an errorCode, and the function turns them into Python exceptions with the description attached, which makes log lines readable later.
import time
import requests
GATE = "https://gatesolver.com"
API_KEY = "YOUR_API_KEY"
class SolveError(Exception):
pass
def gate_post(path: str, payload: dict) -> dict:
payload = {"clientKey": API_KEY, **payload}
reply = requests.post(GATE + path, json=payload, timeout=30).json()
if reply.get("errorId"):
raise SolveError(f'{reply.get("errorCode")}: {reply.get("errorDescription", "")}')
return reply
def solve_checkbox(page_url: str, site_key: str) -> str:
job = gate_post("/createTask", {"task": {
"type": "ReCaptchaV2TaskProxyLess", "websiteURL": page_url,
"websiteKey": site_key,
}})
give_up_at = time.monotonic() + 130
while time.monotonic() < give_up_at:
time.sleep(3)
state = gate_post("/getTaskResult", {"taskId": job["taskId"]})
if state["status"] == "ready":
return state["solution"]["gRecaptchaResponse"]
if state["status"] == "failed":
raise SolveError("task failed, nothing was charged")
raise SolveError("no answer within the time limit")
Notice the sleep comes before the first poll. A token task is never ready the instant it is created, so asking immediately only spends one of your 600 requests per minute. The loop allows a little more than 120 seconds because a task that is still unsolved at that point is marked failed on our side and costs nothing.
Submit the token with the form
When the target is a plain HTML form, you do not need a browser at all. Post the same fields a person's browser would post and add the token under the name g-recaptcha-response. Open the form in your browser's developer tools once to see every field it sends, including hidden ones such as CSRF values.
with requests.Session() as browser_like:
form_page = "https://example.com/contact"
browser_like.get(form_page, timeout=20)
token = solve_checkbox(form_page, read_site_key(form_page))
sent = browser_like.post(form_page, data={
"email": "qa-bot@example.com",
"message": "Automated form check",
"g-recaptcha-response": token,
}, timeout=30)
print(sent.status_code, len(sent.text))
Using a Session keeps any cookies the site set on the first visit, which many back ends tie to the CSRF value. If the site renders its form with JavaScript and posts through an API call, capture that request in the network tab and replay it with the token in whatever field name it uses.
Handle errors the useful way
Not every error deserves a retry. Group them by what your code should do next, and keep the retry count small so a broken configuration does not loop forever.
| errorCode | What it means for your script |
|---|---|
| ERROR_KEY_DENIED_ACCESS | The key is wrong or was replaced. Stop and fix the configuration. |
| ERROR_ZERO_BALANCE | Top up, then resume. Retrying in a loop will not help. |
| ERROR_INVALID_TASK_DATA | The description names the missing field, often an empty site key. |
| ERROR_CAPTCHA_UNSOLVABLE | Free. Create a new task once or twice. |
| ERROR_SERVICE_UNAVAILABLE | Free. Wait a few seconds and retry. |
| ERROR_RATE_LIMIT | Over 600 requests a minute. Poll less often or spread the work. |
A good pattern is a wrapper that retries only the transient codes, with a short pause in between, and lets the others raise. The full meaning of each code is listed in the API docs.
When the site still rejects the token
A ready token can still be refused. The usual causes are simple: the token was submitted more than two minutes after it was issued, it was sent twice, the page URL in the task did not match the real page, or the widget was actually the invisible variant. Solve right before the submit, never cache tokens, and read why reCAPTCHA tokens expire if timing is tight. If the page shows the badge instead of a checkbox, switch to the steps for invisible reCAPTCHA.
Some sites also compare the visitor's IP between page load and submit. In that case use the ReCaptchaV2Task type with a proxy field so the solve happens from the same address your session uses.
Switching to a proxy task
The change is two lines in the task dictionary: set "type": "ReCaptchaV2Task" and add "proxy": "http://user:pass@host:port" with the same proxy your Session sends traffic through (browser_like.proxies = {"https": proxy_url}). Everything else in the client stays as it is. Use the proxyless type by default and reach for the proxy version only when you can see the site reject otherwise valid tokens, because the extra hop adds a little time to every solve. Our note on proxyless or proxy tasks goes through the trade-off in more detail.
Finally, log the task id next to every submit. When a page starts refusing tokens, being able to match a refusal to the exact task, its timestamp and the page URL you sent turns an afternoon of guessing into a five minute check.
Common questions
Which Python versions does this example support?
The code uses the str | None type hint, so it needs Python 3.10 or newer. Replace it with Optional[str] to run on 3.9.
Can I solve several checkboxes at the same time?
Yes. There is no limit on concurrent tasks, so you can run the solve function from a thread pool; just keep total API calls under 600 per minute per key.
Do I pay for a task that times out?
No. A task that is not solved within 120 seconds is marked failed and is free, as are unsolvable tasks and error responses.
Is a browser required to use the token?
Not for plain HTML forms. Posting the token with the other form fields through requests is enough when the site does not depend on JavaScript to submit.
What does the userAgent in the solution mean?
It is the browser identity the token was produced under. Sending the same User-Agent header with your submit can help on sites that compare them.
Keep reading
- reCAPTCHA v2 solver$0.56 per 1,000 tasks, answers under 9 seconds.
- Find the reCAPTCHA site keyFive dependable places to read a reCAPTCHA site key, from the data-sitekey attribute to the k parameter in network requests.
- g-recaptcha-responseThe hidden textarea that carries a reCAPTCHA token to the server, and how to fill it with a solved answer.
- API docscreateTask, getTaskResult, getBalance, error codes and the in.php format.