reCAPTCHA
How to solve reCAPTCHA v3 in Python
reCAPTCHA v3 never shows a challenge; the site asks for a token in the background and sends it with an ordinary request. Your Python code has to do the same, with the same action name the page uses.
What changes from v2
With reCAPTCHA v3 there is nothing to click and nothing to fill. The page loads api.js?render=SITE_KEY, and when the visitor does something that matters (logs in, searches, checks out) a script calls grecaptcha.execute(SITE_KEY, {action: 'login'}). The resulting token goes to the site's own API in a JSON field or form value, and the site's server asks Google for a score between 0.0 and 1.0.
So in Python you need three facts from the page, not two: the page URL, the site key and the action name. Then you have to find the request that carries the token, because that is where your token must go. There is no textarea to fill.
Collect the site key and action
The site key is the render= value in the script URL. The action is the string passed to execute. Both are visible in the page source or the bundled JavaScript, and a short search usually finds them.
import re
import httpx
def v3_params(url: str) -> dict:
page = httpx.get(url, follow_redirects=True, timeout=20).text
key = re.search(r"recaptcha/(?:api|enterprise)\.js\?[^\"']*render=([\w-]+)", page)
act = re.search(r"execute\([^)]*action\s*:\s*['\"]([\w/]+)['\"]", page)
return {"websiteKey": key.group(1) if key else None,
"pageAction": act.group(1) if act else None}
If the action lives in a separate bundle, the regex will not find it in the HTML. Search the scripts in your browser's developer tools instead, as described in the guide on how to find the reCAPTCHA v3 action name. Guessing is a bad idea: when the action in the token does not match what the server expects, the site can refuse the request no matter what the score is.
Build a small solver with httpx
This client uses httpx and a dataclass for the task, so the field names are written once and checked by your editor. Install it with pip install httpx.
import time
from dataclasses import dataclass, asdict
import httpx
@dataclass
class V3Task:
websiteURL: str
websiteKey: str
pageAction: str
type: str = "ReCaptchaV3TaskProxyLess"
class GateError(Exception):
"""Raised when the API answers with errorId 1."""
class ScoreSolver:
def __init__(self, api_key: str):
self.api_key = api_key
self.client = httpx.Client(base_url="https://gatesolver.com", timeout=30)
def _send(self, endpoint: str, **fields) -> dict:
data = self.client.post(endpoint, json={"clientKey": self.api_key, **fields}).json()
if data.get("errorId"):
raise GateError(data.get("errorCode"), data.get("errorDescription"))
return data
def token_for(self, task: V3Task) -> tuple[str, str]:
task_id = self._send("/createTask", task=asdict(task))["taskId"]
for _ in range(40):
time.sleep(3)
info = self._send("/getTaskResult", taskId=task_id)
if info["status"] == "ready":
sol = info["solution"]
return sol["gRecaptchaResponse"], sol.get("userAgent", "")
if info["status"] == "failed":
break
raise GateError("NO_TOKEN", f"task {task_id} ended without a token")
token_for returns the user agent along with the token. That string describes the browser profile the token was produced under; using it as your User-Agent header when you call the site keeps the two consistent. Each solved task costs $0.70 per 1,000 and typically arrives under 3 seconds.
Find the request that carries the token
Open the page in a browser, open the network panel, and perform the action once by hand. Look for the request that fires right after the reload call to Google. Its body contains a long string starting with something like 03A; that is the v3 token, and the field name next to it is what your code must use. Common names are g-recaptcha-response, token, captcha and recaptchaToken, but only the network panel tells you for sure.
Note the other parts of the request too: headers such as X-Requested-With or a CSRF header, cookies set by the page, and whether the body is JSON or form encoded. Your Python request needs all of them, otherwise the server may refuse it for reasons unrelated to the CAPTCHA.
Send it the way the page does
solver = ScoreSolver("YOUR_API_KEY")
login_page = "https://example.com/login"
p = v3_params(login_page)
token, agent = solver.token_for(V3Task(login_page, p["websiteKey"], p["pageAction"] or "login"))
with httpx.Client(headers={"User-Agent": agent or "Mozilla/5.0"}, follow_redirects=True) as site:
site.get(login_page) # picks up session cookies
resp = site.post("https://example.com/api/session", json={
"username": "monitor@example.com",
"password": "from-your-secret-store",
"recaptchaToken": token,
})
print(resp.status_code, resp.headers.get("content-type"))
The endpoint and field names here are placeholders for whatever you saw in the network panel. Notice that the token is requested only after the parameters are known and right before the call. A v3 token, like a v2 token, is valid for about two minutes and only once.
Why a token can be accepted by the API but not the site
The site, not the solver, decides what score is good enough, and it often checks more than the score. If your request is refused, work through this list:
- Action mismatch. The server compares the action inside the token with the one it expects for that endpoint. Use the exact string from the page.
- Threshold. Some sites require a high score for sensitive actions such as signup. You cannot change the threshold; you can make sure the action is right and the request looks like the page's own.
- Network consistency. When the site compares IPs, switch to
ReCaptchaV3Taskand pass the proxy your httpx client uses in theproxyfield. - Missing context. A missing cookie or CSRF header can produce the same error message as a bad token. Replay the page's request faithfully.
The article on reCAPTCHA v3 scores explains what the site sees on its side. If the script tag loads enterprise.js instead of api.js, you need the Enterprise task described in solving reCAPTCHA Enterprise.
When the page calls execute on load
Some sites request a v3 token as soon as the page opens, store it in a hidden input, and refresh it on a timer. In that case the request that carries the token may be the form post itself, with a field such as g-recaptcha-response or recaptcha_token already in the HTML. The approach stays the same: solve with the action the page uses (often homepage or the form name), then put the fresh token into that field when you post. Do not reuse a token you scraped from the HTML; it was issued to a different visitor and has likely expired.
Running it on a schedule
Typical v3 jobs are monitoring tasks: logging into your own account on a supplier portal every morning, or checking that a public search page still returns results. Create the ScoreSolver once per process so its connection pool is reused, catch GateError around each run, and retry once on ERROR_CAPTCHA_UNSOLVABLE or ERROR_SERVICE_UNAVAILABLE, both of which are free. All task fields are listed on the reCAPTCHA v3 page.
Common questions
Can I skip pageAction in a v3 task?
The API accepts tasks without it, but most sites check the action, so send the exact value the page passes to grecaptcha.execute.
Can I choose the score I get?
No. The score comes from Google and the site decides what is acceptable. You control the action, the timing and how closely your request matches the page.
Why does the solution include a userAgent?
It is the browser profile the token was produced under. Sending it as your User-Agent header keeps the token and the request consistent.
Can I use requests instead of httpx?
Yes. The example uses httpx for its base_url option, but the same calls work with requests.Session.
How long does a v3 token stay valid?
About two minutes, and it can be verified only once. Request it right before the call that needs it.
Keep reading
- reCAPTCHA v3 solver$0.70 per 1,000 tasks, answers under 3 seconds.
- Find the reCAPTCHA v3 action nameLocate the exact action string a page passes to grecaptcha.execute using script search, breakpoints or the outgoing request.
- reCAPTCHA v3 scores explainedHow Google turns page signals into a v3 score, how sites act on it, and what a solver can and cannot influence.
- pageAction (reCAPTCHA action)The action label a page passes to grecaptcha.execute, how to locate it, and why a wrong label sinks good tokens.