Cloudflare: solving Challenge
TIP
Create the task with the createTask method and get the result with the getTaskResult method.
Note
- Proxy is necessary, please use Static proxy or Sticky proxy instead of Rotating proxy.
- Custom userAgent is not currently supported, please use the headers and cookies returned by our API.
- If you fail to get the solution, your IP may be blocked, please try to change your proxy.
- You have to use the TLS request library to request the target website.
Type | Note | State |
---|---|---|
challenge | stable |
The task type type
is as follows
AntiCloudflareTask
Create Task
Create the task with the createTask.
Task Object Structure
Properties | Type | Required | Description |
---|---|---|---|
type | String | Required | AntiCloudflareTask |
websiteURL | String | Required | The address of the target page. |
proxy | String | Required | Your Static proxy or Sticky proxy. Learn Using proxies |
Example Request
POST https://api.capsolver.com/createTask
Host: api.capsolver.com
Content-Type: application/json
{
"clientKey": "YOUR_API_KEY",
"task": {
"type": "AntiCloudflareTask",
"websiteURL": "https://www.yourwebsite.com",
"proxy": "ip:port:user:pass"
}
}
Example Response
{
"errorId": 0,
"status": "idle",
"taskId": "df944101-64ac-468d-bc9f-41baecc3b8ca"
}
Getting Result
Use the getTaskResult method to get the recognition results
Depending on the website and proxy, you will get the results within the interval of 2s
to 20s
Example Request
POST https://api.capsolver.com/getTaskResult
Host: api.capsolver.com
Content-Type: application/json
{
"clientKey": "YOUR_API_KEY",
"taskId": "df944101-64ac-468d-bc9f-41baecc3b8ca"
}
Example Response
{
"errorId": 0,
"taskId": "df944101-64ac-468d-bc9f-41baecc3b8ca",
"status": "ready",
"errorCode": "",
"errorDescription": "",
"success": true,
"solution": {
"cookies": "cf_clearance=_VPCTZXP5bhinm8NrzK65xQPEK6NZHH...; SESSION=91e85415-5da1-4431-abd5-15dde63df5bc; _cfuvid=oMqJBbUZ5a1rgjnfTGAVSRu0qZPJHm3R8YPqt.4vM6s-1735225592444-0.0.1.1-605900000",
"headers": {
"sec-ch-ua": "\"Chromium\";v=\"130\", \"Google Chrome\";v=\"130\", \"Not?A_Brand\";v=\"99\"",
"sec-ch-ua-platform": "\"Windows\"",
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36",
"sec-ch-ua-mobile": "?0",
"sec-fetch-user": "?1",
"referer": "https://www.yourwebsite.com",
"Sec-Fetch-Dest": "document",
"Sec-Fetch-Mode": "navigate",
"Sec-Fetch-Site": "same-origin",
"accept-language": "en",
},
"page_url": "https://www.yourwebsite.com",
"proxy": "your proxy...",
"token": "_VPCTZXP5bhinm8NrzK65xQPEK6NZHH..."
}
}
Use SDK Request
# pip install --upgrade capsolver
# export CAPSOLVER_API_KEY='...'
import capsolver
# capsolver.api_key = "..."
solution = capsolver.solve({
"type": "AntiCloudflareTask",
"websiteURL": "https://www.yourwebsite.com",
"proxy": "ip:port:user:pass"
})
Sample Code
# pip install requests
import requests
import time
api_key = "YOUR_API_KEY" # your api key of capsolver
def capsolver():
payload = {
"clientKey": api_key,
"task": {
"type": "AntiCloudflareTask",
"websiteURL": "https://www.yourwebsite.com",
"proxy": "ip:port:user:pass"
}
}
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(1) # 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", {})
if status == "failed" or resp.get("errorId"):
print("Solve failed! response:", res.text)
return
token = capsolver()
print(token)