Guide
Task(Token)
reCAPTCHA v2

ReCaptchaV2: solving reCAPTCHA v2

TIP

Create the task with the createTask method and get the result with the getTaskResult method.

The task type types that we support:

  • ReCaptchaV2TaskProxyLess is using the server’s built-in proxy.
  • ReCaptchaV2EnterpriseTask this task type require your own proxies.
  • ReCaptchaV2EnterpriseTaskProxyLess is using the server’s built-in proxy.

Create Task

Create a task with the createTask method.

Before creating a task, you can learn the following

If you got invalid response, you can learn the following

Task Object Structure

PropertiesTypeRequiredDescription
typeStringRequiredReCaptchaV2TaskProxyLess
ReCaptchaV2EnterpriseTask
ReCaptchaV2EnterpriseTaskProxyLess
websiteURLStringRequiredThe URL of the target webpage that loads the captcha, It’s best to submit the full URL instead of just the host.
websiteKeyStringRequiredRecaptcha website key.
proxyStringOptionalLearn Using proxies.
pageActionStringOptionalFor ReCaptchaV2, if there is an sa parameter in the payload of the /anchor endpoint, please submit its value
recaptchaDataSValueStringOptionalFor ReCaptchaV2 normal version, if there is an s parameter in the payload of the /anchor endpoint, please submit its value
enterprisePayloadObjectOptionalFor ReCaptchaV2 enterprise version, if there is an s parameter in the payload of the /anchor endpoint, please submit its value
isInvisibleBoolOptionalPass true if there is no “I’m not a robot” checkbox but the challenge will still appear, usually required in v2 invisible mode.
isSessionBoolOptionalSession mode, when enabled, will return a recaptcha-ca-t value, which is used as a cookie. It usually appears in v3.

Note: Some websites require a recaptcha-ca-e value, which usually appears in v2. If this value is present, it will be automatically returned without any additional parameter settings.
apiDomainStringOptionalThe domain name for loading the captcha. Usually, this parameter does not need to be passed.
http://www.google.com/
http://www.recaptcha.net/
WARNING

If you are not sure how to pass the parameters, please refer to our blog to use the capsolver extension to automatically obtain the parameters.

If the V2 score you get is low, please use CapSolver extension to identify the json data and send to us for optimization.

Example Request

POST https://api.capsolver.com/createTask
Host: api.capsolver.com
Content-Type: application/json
{
  "clientKey": "YOUR_API_KEY",
  "task": {
    "type": "ReCaptchaV2Task",
    "websiteURL": "https://www.google.com/recaptcha/api2/demo",
    "websiteKey": "6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-",
    "enterprisePayload": {
      "s": "SOME_ADDITIONAL_TOKEN" // Optional
    },
    "isInvisible": false, // Optional
    "pageAction": "submit", // Optional
    "apiDomain": "", // Optional
    "proxy": "http:ip:port:user:pass", // socks5:ip:port:user:pass, Optional
  }
}

After you submit the task to us, you should receive in the response a ‘taskId’ if it’s successful. Please read errorCode: full list of errors if you didn’t receive the task id.

Example Response

{
    "errorId": 0,
    "errorCode": "",
    "errorDescription": "",
    "taskId": "61138bb6-19fb-11ec-a9c8-0242ac110006" 
}

Getting Results

After you have the taskId, you need to submit the taskId to retrieve the solution. Response structure is explained in getTaskResult.

Depending on the system load, you will get the results within the interval of 1s to 10s

Example Request

POST https://api.capsolver.com/getTaskResult
Host: api.capsolver.com
Content-Type: application/json
 
{
    "clientKey": "YOUR_API_KEY",
    "taskId": "61138bb6-19fb-11ec-a9c8-0242ac110006"
}

Example Response

{
    "errorId": 0,
    "errorCode": null,
    "errorDescription": null,
    "solution": {
        "userAgent": "xxx", // User-Agent
        "createTime": 1671615324290, // The creation time of the token
        "gRecaptchaResponse": "3AHJ......", // token
        "recaptcha-ca-t": "AbEM......", // Some v3 websites have session mode. After enabling isSession, this parameter will be returned and used as a cookie.
        "recaptcha-ca-e": "Abp_......" // Some v2 websites have this parameter, which is used as a cookie. If there is such a value, it will be automatically returned.
    },
    "status": "ready"
}

Use SDK Request

#pip install --upgrade capsolver
#export CAPSOLVER_API_KEY='...'
 
import capsolver
# capsolver.api_key = "..."
solution = capsolver.solve({
            "type": "ReCaptchaV2TaskProxyLess",
            "websiteURL": "https://www.google.com/recaptcha/api2/demo",
            "websiteKey": "6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-",
          })

Sample Code

# pip install requests
import requests
import time
 
# TODO: set your config
api_key = "YOUR_API_KEY"  # your api key of capsolver
site_key = "6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-"  # site key of your target site
site_url = "https://www.google.com/recaptcha/api2/demo"  # page url of your target site
 
 
def capsolver():
    payload = {
        "clientKey": api_key,
        "task": {
            "type": 'ReCaptchaV2TaskProxyLess',
            "websiteKey": site_key,
            "websiteURL": site_url
        }
    }
    res = requests.post("https://api.capsolver.com/createTask", json=payload)
    resp = res.json()
    task_id = resp.get("taskId")
    if not task_id:
        print("Failed to create task:", res.text)
        return
    print(f"Got taskId: {task_id} / Getting result...")
 
    while True:
        time.sleep(3)  # delay
        payload = {"clientKey": api_key, "taskId": task_id}
        res = requests.post("https://api.capsolver.com/getTaskResult", json=payload)
        resp = res.json()
        status = resp.get("status")
        if status == "ready":
            return resp.get("solution", {}).get('gRecaptchaResponse')
        if status == "failed" or resp.get("errorId"):
            print("Solve failed! response:", res.text)
            return
 
 
token = capsolver()
print(token)