Skip to content

Submit a reCAPTCHA token

The gRecaptchaResponse YesCaptcha returns is the same value Google hands to a page after someone completes the captcha. Once you have it, you must submit it to the target site (not to Google or YesCaptcha) the same way a browser would; the site verifies it with Google and lets you through. There are two ways: send the request yourself, or put the token into the page in a real browser and submit.

Normally:

  1. The page loads reCAPTCHA and the user completes it;
  2. Google gives the page a token, which the page puts in the g-recaptcha-response textarea (or passes to a callback);
  3. The user submits the form and the token goes to the site’s server with it;
  4. The site’s server verifies the token with Google and lets the user through.

With YesCaptcha, steps 1 and 2 are done for you: create a task with websiteURL and websiteKey, get the token, and continue from step 3.

Tokens are single use and valid for about 120 seconds; submit within 60 seconds.

Section titled “Method 1: send the request yourself (recommended)”
  1. Do it once by hand in a browser: open the Network panel (F12), complete the captcha, submit, and find the request that submits the form.
  2. In its Payload (or Form Data), find the field carrying the token, usually g-recaptcha-response, with a value starting with 03A. Some sites rename it, for example grecaptcharesponse or captcha.
  3. Send the same request from your program with that field set to the YesCaptcha token. The other fields, cookies and headers must also match the browser’s, since sites often check them too.

A complete example on Google’s demo page: get a token, then post it back to the demo page in the g-recaptcha-response field:

recaptcha_requests.py
"""Solve reCAPTCHA v2 on Google's demo page and submit the token with plain HTTP (no browser).
Run: pip install requests
export YESCAPTCHA_CLIENT_KEY=your_client_key
python recaptcha_requests.py
Each run creates one NoCaptchaTaskProxyless task (charged per the price list).
"""
import os
import time
import requests
CLIENT_KEY = os.environ["YESCAPTCHA_CLIENT_KEY"]
API = "https://api.yescaptcha.com"
WEBSITE_URL = "https://www.google.com/recaptcha/api2/demo"
WEBSITE_KEY = "6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-"
def call(method, payload):
data = requests.post(f"{API}/{method}", json={"clientKey": CLIENT_KEY, **payload}, timeout=30).json()
if data.get("errorId"):
raise RuntimeError(f"{data.get('errorCode')}: {data.get('errorDescription')}")
return data
def get_token():
task = {"type": "NoCaptchaTaskProxyless", "websiteURL": WEBSITE_URL, "websiteKey": WEBSITE_KEY}
task_id = call("createTask", {"task": task})["taskId"]
for _ in range(36): # poll every 5 seconds, for up to about 3 minutes
time.sleep(5)
result = call("getTaskResult", {"taskId": task_id})
if result.get("status") == "ready":
return result["solution"]["gRecaptchaResponse"]
raise TimeoutError(task_id)
token = get_token()
print("token:", token[:40], "...")
# Submit the token the same way the browser does: the demo form posts the field
# "g-recaptcha-response" back to the page. Check your own site's request in DevTools > Network.
page = requests.post(WEBSITE_URL, data={"g-recaptcha-response": token}, timeout=30)
print("passed" if "Verification Success" in page.text else "not passed", page.status_code)

Method 2: fill it into the page (Selenium and similar)

Section titled “Method 2: fill it into the page (Selenium and similar)”

When you drive a real browser with Selenium, Playwright and similar tools:

  1. Read data-sitekey from the page and create a task with it to get a token.
  2. Write the token into the page’s g-recaptcha-response textarea.
  3. If the page has a callback (data-callback="..."), call it with the token; on some sites the submit button only becomes clickable after the callback runs.
  4. Submit the form.
// Step 2: write the token (run in the page)
document.getElementById('g-recaptcha-response').value = 'TOKEN';
// Step 3: call the callback if there is one, e.g. data-callback="onSuccess"
onSuccess('TOKEN');

With several reCAPTCHAs on a page the textarea may be g-recaptcha-response-1 and so on. If you can’t find it, complete the captcha by hand once and search the Elements panel for 03A to see where the result is stored. How to find the callback: Find reCAPTCHA parameters.

A complete example (Selenium 4):

recaptcha_selenium.py
"""Solve reCAPTCHA v2 on Google's demo page in a real browser with Selenium 4:
get a token from YesCaptcha, put it into the page, then submit the form.
Run: pip install requests selenium
export YESCAPTCHA_CLIENT_KEY=your_client_key
python recaptcha_selenium.py
Each run creates one NoCaptchaTaskProxyless task (charged per the price list).
"""
import os
import time
import requests
from selenium import webdriver
from selenium.webdriver.common.by import By
CLIENT_KEY = os.environ["YESCAPTCHA_CLIENT_KEY"]
API = "https://api.yescaptcha.com"
WEBSITE_URL = "https://www.google.com/recaptcha/api2/demo"
def call(method, payload):
data = requests.post(f"{API}/{method}", json={"clientKey": CLIENT_KEY, **payload}, timeout=30).json()
if data.get("errorId"):
raise RuntimeError(f"{data.get('errorCode')}: {data.get('errorDescription')}")
return data
def get_token(website_url, website_key):
task = {"type": "NoCaptchaTaskProxyless", "websiteURL": website_url, "websiteKey": website_key}
task_id = call("createTask", {"task": task})["taskId"]
for _ in range(36):
time.sleep(5)
result = call("getTaskResult", {"taskId": task_id})
if result.get("status") == "ready":
return result["solution"]["gRecaptchaResponse"]
raise TimeoutError(task_id)
driver = webdriver.Chrome() # Selenium 4 downloads a matching chromedriver automatically
try:
driver.get(WEBSITE_URL)
site_key = driver.find_element(By.CSS_SELECTOR, "[data-sitekey]").get_attribute("data-sitekey")
token = get_token(WEBSITE_URL, site_key)
# Put the token where reCAPTCHA keeps it ...
driver.execute_script(
"document.getElementById('g-recaptcha-response').value = arguments[0];", token
)
# ... and, if the page uses a callback (data-callback="..."), call it:
callback = driver.find_element(By.CSS_SELECTOR, "[data-sitekey]").get_attribute("data-callback")
if callback:
driver.execute_script(f"window[{callback!r}](arguments[0]);", token)
driver.find_element(By.ID, "recaptcha-demo-submit").click()
time.sleep(2)
print("passed" if "Verification Success" in driver.page_source else "not passed")
finally:
driver.quit()

v3 has no checkbox. The page calls grecaptcha.execute(SITE_KEY, {action: '...'}) when it needs a token and puts the token into its own request (the field name is up to the site; common ones are g-recaptcha-response, token and recaptchaToken). Use Method 1: find the request carrying the token in the Network panel and reproduce it. The task’s pageAction must match the page’s action.

  • The token expired: submit right away, within 60 seconds.
  • You submitted the wrong field, or missed other fields or cookies: compare with the browser’s request field by field.
  • The site also checks IP and User-Agent: use a type with your own proxy (such as NoCaptchaTask) and submit through the same proxy.
  • v3 score too low: check pageAction, or use a fixed high-score type; see reCAPTCHA v3.
  • The site’s risk checks look at other behaviour signals. If tokens pass too rarely, switch to image recognition and click in a real browser, or use the browser extension.