跳转到主要内容
指南

Decodo(Smartproxy)住宅代理配合 NSLSolver:用 Python 和 Node.js 获取 Kasada 请求头、Akamai Cookie 与 cf_clearance

NSLSolver 团队发布于 9 分钟阅读

Decodo 是 2025 年 4 月之前名为 Smartproxy 的代理服务商,其住宅代理通过同一个网关 gate.decodo.com:7000 提供。本文介绍如何把 Decodo 住宅代理交给 NSLSolver,让 Kasada x-kpsdk 请求头、Akamai _abck cookie 和 Cloudflare cf_clearance cookie 都在你随后发送请求的同一个出口 IP 上生成,并提供完整的 Python 与 Node.js 代码。

NSLSolver 在服务端求解,不使用浏览器,只对成功的求解计费。Cloudflare Challenge、reCAPTCHA v3 和 Akamai 必须使用代理,因为结果与获得它的 IP 绑定。Decodo 的会话参数决定这个 IP 能否保持足够长的时间供你使用。

Decodo 住宅代理格式速览

网关
gate.decodo.com:7000(HTTP、HTTPS、SOCKS5)
认证
user-USERNAME-<参数>:PASSWORD
粘性会话
-session-<任意字符串>(默认 10 分钟)
会话时长
-sessionduration-<1 至 1440 分钟>
地理定位
-country-us -state-us_california -city-new_york -zip-10001
完整示例
http://user-USERNAME-country-us-session-a1b2c3d4-sessionduration-30:PASSWORD@gate.decodo.com:7000

来自 Decodo 住宅代理文档(help.decodo.com),2026 年 12 月 1 日核对。USERNAME 与 PASSWORD 为 Decodo 控制台中的代理凭据。

哪些 NSLSolver 求解需要 Decodo 代理?

NSLSolver 通过哪个 IP 求解,后续请求就必须从哪个 IP 发出。把 Decodo 代理 URL 填入 POST https://api.nslsolver.com/solve 的 proxy 字段,然后让你自己的请求走完全相同的 URL,包括相同的会话 ID。

求解类型代理与 IP 绑定的内容NSLSolver 每 1,000 次价格
Cloudflare Challenge必需cf_clearance cookie$1.00
Akamai Bot Manager(测试版)必需_abck 与 bm_sz cookie$2.00
reCAPTCHA v3必需分数取决于 IP$1.00
Kasada可选,建议使用x-kpsdk-ct 会话$1.50
Cloudflare Turnstile可选(默认无需代理)默认无$0.80

只对成功的求解计费。Decodo 按你的 Decodo 套餐单独收取代理流量费用。

Decodo 住宅代理 URL 的构成

Decodo 把所有定位选项都写在用户名里。在 gate.decodo.com:7000 上只用 username:password 时,每个请求都会换一个随机 IP。一旦加入任何参数,用户名必须以 user- 开头,后接你的代理用户名和键值对,全部用连字符连接。密码保持不变。

Decodo 也支持按端口定位:在 gate.decodo.com 上,10001 至 49999 端口为粘性、7000 与 10000 端口为轮换;us.decodo.com 等国家主机用 10001 至 29999 表示粘性、10000 表示轮换。下面的代码使用用户名参数,因为这样会话 ID 和时长一目了然。

参数示例Decodo 文档说明
countrycountry-us两位国家代码,Decodo 示例中为小写。
statestate-us_california美国州,需带 us_ 前缀。
citycity-new_york与 country 一起使用;空格写成下划线。
zipzip-10001仅限美国。
sessionsession-a1b2c3d4任意字符串。保持同一 IP,默认 10 分钟。
sessiondurationsessionduration-30粘性时长(分钟),1 至 1440。

Decodo 还提供 asn、continent 和 geohash 参数;city 与 ASN 不能同时使用。SOCKS5 只能用于 gate.decodo.com,不能用于国家主机。Decodo 表示旧的 Smartproxy 接入点仍可使用,但当前文档使用 gate.decodo.com。

cf_clearance、_abck 与 Kasada:用粘性会话还是轮换?

cf_clearance 只在获得它的 IP 上有效,且只在网站的 Challenge Passage 时长内有效(默认 30 分钟)。不带 session 参数的 Decodo URL 会让每个请求都从新 IP 发出,cookie 在下一个请求就失效了。加上 session-<id>,并把 sessionduration 设为不短于你打算复用 cookie 的时间;sessionduration-30 正好对应默认的 Challenge Passage。

Akamai 同理:_abck 由一个客户端在一个 IP 上获得,换了出口 IP 就像另一个访问者拿着别人的 cookie。对于 Kasada,求解和调用受保护接口要在同一个 IP 上完成,并且每次调用仍要发送新的 x-kpsdk-cd。

轮换依然有用,只是要放在更高一层:每个工作进程使用自己的会话 ID;当网站开始拦截某个 IP 时,为该进程换一个新的会话 ID 并重新求解。如果 Decodo 在会话到期前不得不把会话换到另一个 IP,cookie 同样会失效;检测到挑战或 403 时重新求解即可。

地理位置一致也很重要。网站常按国家提供不同内容或更严格的规则,通过德国 IP 获得、却从美国 IP 回放的 cookie 属于另一个访问者。选定一个国家,在求解和回放时都把它写在 Decodo 用户名中;对于 Cloudflare Challenge,再传入 accept_language,让求解时的 Accept-Language 与该国家一致。

Python:通过 Decodo 粘性会话求解 Cloudflare Challenge

辅助函数负责拼出 Decodo URL。同一个字符串既传给 NSLSolver,也传给 curl_cffi,后者以类似 Chrome 的 TLS 指纹发送请求。回放 cf_clearance 时要同时使用 API 返回的 user_agent。

decodo_nslsolver.py
# decodo_nslsolver.py  (pip install curl_cffi)
import secrets
from curl_cffi import requests

NSL_API_KEY = "nsl_YOUR_API_KEY"
DECODO_USERNAME = "YOUR_DECODO_USERNAME"  # proxy user from the Decodo dashboard
DECODO_PASSWORD = "YOUR_DECODO_PASSWORD"
UA = ("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
      "(KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36")


def decodo_proxy(country="us", session=None, minutes=30):
    """Decodo residential gateway. Targeting goes in the username, which must
    start with "user-" once any parameter is present. No session = new IP
    on every request."""
    user = f"user-{DECODO_USERNAME}-country-{country}"
    if session:
        user += f"-session-{session}-sessionduration-{minutes}"
    return f"http://{user}:{DECODO_PASSWORD}@gate.decodo.com:7000"


def solve(payload):
    r = requests.post(
        "https://api.nslsolver.com/solve",
        headers={"X-API-Key": NSL_API_KEY},
        json=payload,
        timeout=180,
    )
    data = r.json()
    if r.status_code != 200 or not data.get("success"):
        raise RuntimeError(f"NSLSolver {r.status_code}: {data.get('error', data)}")
    return data


def browser_session(proxy, user_agent, impersonate="chrome"):
    # TLS fingerprint must match the UA: "chrome" for a Chrome UA, "safari_ios"
    # for the iPhone Safari UA that a Challenge solve returns
    s = requests.Session(impersonate=impersonate)
    s.proxies = {"http": proxy, "https": proxy}
    s.headers["User-Agent"] = user_agent
    return s


# One sticky US IP for 30 minutes: the solve and every replayed request use it.
cf_proxy = decodo_proxy("us", session=secrets.token_hex(4), minutes=30)

cf = solve({
    "type": "challenge",
    "url": "https://cf-protected.example.com/",
    "site_key": "0x4AAAAAAA...",          # challenge widget id of the target
    "proxy": cf_proxy,
    "accept_language": "en-US,en;q=0.9",  # match the proxy country
})
site = browser_session(cf_proxy, cf["user_agent"], impersonate="safari_ios")  # replay the returned UA
site.headers["Accept-Language"] = "en-US,en;q=0.9"
for name, value in cf["cookies"].items():  # cf_clearance
    site.cookies.set(name, value)

r = site.get("https://cf-protected.example.com/catalog")
print(r.status_code, r.headers.get("cf-mitigated"))  # 200 None when accepted

Python:通过 Decodo 获取 Kasada x-kpsdk 请求头

在浏览器 Network 面板中找到 p_js_path、fp_host 和 tl_host:分别是 p.js 脚本、提供 /fp 的主机和接收 POST /tl 的主机。响应包含 x-kpsdk-ct、x-kpsdk-cd、x-kpsdk-v 和 x-kpsdk-h;大多数网站的 x-kpsdk-cd 只能使用一次,所以每次受保护调用都要重新求解。

decodo_nslsolver.py
# Same file: Kasada headers minted on the IP that calls the protected API.
kasada_proxy = decodo_proxy("us", session=secrets.token_hex(4), minutes=30)

k = solve({
    "type": "kasada",
    "url": "https://www.kasada-site.example.com/login",
    "user_agent": UA,
    "ua_version": 145,  # Chrome major version of UA
    "kasada_config": {
        "p_js_path": "/<uuid-1>/<uuid-2>/p.js",       # the target's real p.js path (DevTools > Network)
        "fp_host": "www.kasada-site.example.com",     # host serving /fp
        "tl_host": "api.kasada-site.example.com",     # host receiving POST /tl
    },
    "proxy": kasada_proxy,
})

api = browser_session(kasada_proxy, UA)
r = api.post(
    "https://api.kasada-site.example.com/v1/search",
    headers=k["headers"],  # x-kpsdk-ct, x-kpsdk-cd, x-kpsdk-v, x-kpsdk-h
    json={"q": "..."},
)
print(r.status_code)  # 429 = a header was rejected; x-kpsdk-cd is single-use

Python:通过 Decodo 获取 Akamai _abck cookie

Akamai 需要同时提供 proxy 和 user_agent。从同一个 Decodo 会话、用同一个 User-Agent 发送返回的全部 cookie,而不只是 _abck。Akamai 在 NSLSolver 上处于测试阶段。

decodo_nslsolver.py
# Same file: Akamai cookies earned and replayed on one Decodo session.
akamai_proxy = decodo_proxy("us", session=secrets.token_hex(4), minutes=30)

ak = solve({
    "type": "akamai",
    "url": "https://akamai-site.example.com/login",  # a page that loads the sensor
    "user_agent": UA,                                # replay this exact UA
    "proxy": akamai_proxy,                           # required for akamai
})

shop = browser_session(akamai_proxy, UA)
for name, value in ak["cookies"].items():  # _abck, bm_sz, ...
    shop.cookies.set(name, value)

r = shop.get("https://akamai-site.example.com/api/products")
print(r.status_code)  # 403 with "Reference #" = blocked again: solve again

Node.js:用 undici 实现同样的三个流程

undici 的 ProxyAgent 会从代理 URL 中读取凭据,所以 Decodo 字符串可以直接使用。如果密码包含 @ 或 : 等字符,请用 encodeURIComponent 编码。

decodo-nslsolver.mjs
// decodo-nslsolver.mjs  (Node 18+, npm i undici)
import { randomBytes } from "node:crypto";
import { fetch, ProxyAgent } from "undici";

const NSL_API_KEY = "nsl_YOUR_API_KEY";
const DECODO_USERNAME = "YOUR_DECODO_USERNAME";
const DECODO_PASSWORD = "YOUR_DECODO_PASSWORD";
const UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 " +
  "(KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36";

// user- prefix + hyphen-joined parameters; a new session id = a new sticky IP
function decodoProxy(country, minutes) {
  const session = randomBytes(4).toString("hex");
  const user = "user-" + DECODO_USERNAME + "-country-" + country +
    "-session-" + session + "-sessionduration-" + minutes;
  return "http://" + user + ":" + encodeURIComponent(DECODO_PASSWORD) + "@gate.decodo.com:7000";
}

async function solve(payload) {
  const res = await fetch("https://api.nslsolver.com/solve", {
    method: "POST",
    headers: { "X-API-Key": NSL_API_KEY, "Content-Type": "application/json" },
    body: JSON.stringify(payload),
  });
  const data = await res.json();
  if (!res.ok || !data.success) {
    throw new Error("NSLSolver " + res.status + ": " + (data.error || JSON.stringify(data)));
  }
  return data;
}

const cookieHeader = (cookies) =>
  Object.entries(cookies).map(([k, v]) => k + "=" + v).join("; ");

// 1) Cloudflare Challenge: cf_clearance + user_agent, replayed on the same IP
const cfProxy = decodoProxy("us", 30);
const cf = await solve({
  type: "challenge",
  url: "https://cf-protected.example.com/",
  site_key: "0x4AAAAAAA...",
  proxy: cfProxy,
  accept_language: "en-US,en;q=0.9",
});
const page = await fetch("https://cf-protected.example.com/catalog", {
  dispatcher: new ProxyAgent(cfProxy),
  headers: { "User-Agent": cf.user_agent, "Accept-Language": "en-US,en;q=0.9", Cookie: cookieHeader(cf.cookies) },
});
console.log("challenge", page.status);

// 2) Kasada: x-kpsdk-* headers for one protected call
const kProxy = decodoProxy("us", 30);
const k = await solve({
  type: "kasada",
  url: "https://www.kasada-site.example.com/login",
  user_agent: UA,
  ua_version: 145,
  kasada_config: {
    p_js_path: "/<uuid-1>/<uuid-2>/p.js",     // the target's real p.js path (DevTools > Network)
    fp_host: "www.kasada-site.example.com",   // host serving /fp
    tl_host: "api.kasada-site.example.com",   // host receiving POST /tl
  },
  proxy: kProxy,
});
const api = await fetch("https://api.kasada-site.example.com/v1/search", {
  method: "POST",
  dispatcher: new ProxyAgent(kProxy),
  headers: { ...k.headers, "User-Agent": UA, "Content-Type": "application/json" },
  body: JSON.stringify({ q: "..." }),
});
console.log("kasada", api.status);

// 3) Akamai: _abck and friends, replayed with the same UA and IP
const akProxy = decodoProxy("us", 30);
const ak = await solve({
  type: "akamai",
  url: "https://akamai-site.example.com/login",
  user_agent: UA,
  proxy: akProxy,
});
const products = await fetch("https://akamai-site.example.com/api/products", {
  dispatcher: new ProxyAgent(akProxy),
  headers: { "User-Agent": UA, Cookie: cookieHeader(ak.cookies) },
});
console.log("akamai", products.status);
// Node's fetch does not copy Chrome's TLS fingerprint. If a strict Kasada or
// Akamai site still blocks it, send the follow-up requests with curl_cffi.

完整 NSLSolver API 文档

Decodo 配合 NSLSolver 的常见问题排查

NSLSolver 的所有状态码,以及这些流程可能遇到的 Cloudflare、Kasada 和 Akamai 错误,都在反爬虫错误代码速查中有说明。

现象常见原因解决方法
407 Proxy Authentication Required添加了参数但缺少 user- 前缀,或凭据有拼写错误。用户名以 user- 开头,后接代理用户名,再接参数。
us.decodo.com 上 SOCKS5 连接失败Decodo 只在 gate.decodo.com 上支持 SOCKS5。使用 socks5h://...@gate.decodo.com:7000,或在国家主机上使用 HTTP。
cf_clearance 先被接受,约 10 分钟后变成 403未设置 sessionduration:Decodo 粘性会话默认 10 分钟。加上 sessionduration-30(最多 1440)。
每个请求都遇到新的挑战没有 session 参数,每个请求都从新 IP 发出。加上 session-<id>,求解与回放使用完全相同的代理 URL。
NSLSolver 400 Validation failed代理字符串缺少协议前缀,或缺少必填字段。发送完整 URL:http://user-...:PASSWORD@gate.decodo.com:7000,并查看错误中指出的字段。
NSLSolver 503 Solve failed求解未完成,不计费。按退避策略重试;同一会话反复失败时,换一个新的会话 ID。

相关阅读

常见问题

NSLSolver 能配合 Decodo 住宅代理使用吗?

可以。把完整的 Decodo 代理 URL(例如 http://user-USERNAME-country-us-session-a1b2c3d4-sessionduration-30:PASSWORD@gate.decodo.com:7000)填入 POST /solve 的 proxy 字段。NSLSolver 在服务端通过该 IP 求解,不使用浏览器,你的后续请求也走同一个 URL。

获取 cf_clearance 应该用粘性还是轮换的 Decodo 会话?

用粘性会话。cf_clearance 只在获得它的 IP 上有效,所以要加上 session-<id>,并把 sessionduration 设为不短于你复用 cookie 的时间。30 分钟对应 Cloudflare 默认的 Challenge Passage。

Decodo 更名后 gate.smartproxy.com 还能用吗?

Decodo 表示,2025 年 4 月更名后 Smartproxy 的接入点和 URL 仍可继续使用。其当前文档使用 gate.decodo.com,本文也使用该地址。

Kasada 需要代理吗?

Kasada 的 proxy 字段是可选的,但传入你调用受保护接口时所用的同一个 Decodo 会话,可以让整个 Kasada 会话保持在一个 IP 上,避免因 IP 变化导致的 429。

配合 Decodo 代理使用 NSLSolver 的费用是多少?

NSLSolver 按成功求解计费:Cloudflare Challenge 每 1,000 次 $1.00,Kasada $1.50,Akamai(测试版)$2.00。失败的求解不计费。Decodo 按你的 Decodo 套餐单独收取代理流量费用。

把你的 Decodo 代理接入 NSLSolver

通过你自己的住宅 IP 获取 Kasada 请求头、Akamai cookie 和 cf_clearance,全部在服务端求解,不使用浏览器。只对成功的求解计费,使用 Google、Gmail 或 Proton 注册即可获得免费额度。