会话模式是决定移动代理任务成败的那一个设置,比国家重要,比协议重要。选错一边,每个请求看起来都是新用户;选错另一边,每个请求看起来永远是同一个人。两种都能被认出来。这一页讲清楚三种模式实际怎么跑,以及什么业务该用哪个。
| 模式 | 用户名后缀 | IP 行为 | 典型用途 |
|---|---|---|---|
| 每请求轮换 | ...-global 或 ...-US_California_city_LosAngeles | 每条新连接换出口 | 互相独立的查询:排名、单页、广告检查 |
| 5 分钟粘性 | ...-session 或 ...-session-5m | 最多 5 分钟同一出口 | 登录握手、短表单、先过验证再操作 |
| 1 小时粘性 | ...-session-1h | 最多 1 小时同一出口 | 下单、多页分页、App 会话模拟 |
窗口是上限,不是承诺。真实运营商会把手机在基站之间切换、会断 PDP 上下文、会回收地址,所以粘性会话可能提前结束。把“1 小时就是 1 小时”写死进代码的人,一定会在最关键的那一步断掉;定期读当前出口 IP、变了就重新认证的代码不会。
既然出口由用户名决定,会话就是一个字符串。一次拼好,保持稳定,需要换的时候明确地换:
import requests
USER, PWD = "10001-abc123", "pass456"
GW = "mobile.iplight.net:1086"
def proxy_for(region="US_California_city_LosAngeles", sticky_minutes=None):
if sticky_minutes is None:
suffix = region # 轮换
elif sticky_minutes <= 5:
suffix = region + "-session" # 5 分钟
else:
suffix = region + "-session-1h" # 1 小时
return "http://%s:%s-%s@%s" % (USER, PWD, suffix, GW)
sessions = {}
def get(account_id, url):
key = account_id # 一个账号一个会话
if key not in sessions:
sessions[key] = proxy_for(sticky_minutes=60)
p = sessions[key]
return requests.get(url, proxies={"http": p, "https": p}, timeout=30)一个账号一个会话,绝不要多个账号共用一个粘性出口。拿同一个固定 IP 连开十个注册,正是平台在找的模式——你把移动代理本来要解决的共享 IP 问题又造回来了。
两个 worker 拿到同一个粘性用户名,请求交叉了。现象:返回里出现不相干的页面,或者流程突然要求重新登录。处理:会话 key 必须带账号或任务 ID,会话池要独占发放。
运营商在窗口内把手机切走。现象:已登录状态下的请求返回未登录页面。处理:定期通过同一会话请求一次 api.ipify.org 读当前出口,变了就重新认证。
与网关的 keep-alive 连接把出口钉死了一整轮。现象:发了 500 个请求,只有 1 个 IP。处理:轮换类任务关闭连接复用,或按批开新会话。
地区 token 拼错后静默回退。现象:价格变成别的币种、本地化站点变成别的语言。处理:每轮第一次请求就从出口 IP 断言国家是否符合预期。
不会。计费按流量,不按会话、不按 IP。粘性会话和轮换请求每 GB 价格一样,差别只在运营商怎么路由。所以这个选择应该由目标站的预期决定,永远不该由价格决定。
目前最长 1 小时。需要更长的连续身份就重建会话并重新认证;出口可能变化,流程要能容忍这一点。
受子账号并发限制,没有单独的会话配额。每个并发粘性会话占一条连接,所以并发数和会话数要一起规划。
不是。运营商地址本身与真实手机共享。粘性保证的是你一直用同一个出口,不是没有别人在用。这种共享恰恰是移动 IP 信誉好的原因。
按到网关的新连接。HTTP keep-alive 会让一条连接承载多个请求、共用一个出口,所以测轮换时必须开新连接。
相关内容: 移动代理 · Python 接移动代理 · 移动代理文档 · 哪些业务需要移动代理 · 价格
1 TB 套餐可以同时跑轮换和粘性——开两个子账号,共用一份额度。
Session mode is the single setting that decides whether a task succeeds on mobile — more than the country, more than the protocol. Get it wrong in one direction and every request looks like a new person; get it wrong in the other and every request looks like the same person forever. Both are detectable. Here is how the three modes actually behave and which job each one fits.
| Mode | Username suffix | IP behaviour | Typical use |
|---|---|---|---|
| Per-request rotation | ...-global or ...-US_California_city_LosAngeles | A different exit on each new connection | Independent lookups: SERP, single product pages, ad checks |
| Sticky 5 minutes | ...-session or ...-session-5m | Same exit for up to 5 minutes | Login handshake, short form fills, captcha-then-act flows |
| Sticky 1 hour | ...-session-1h | Same exit for up to 1 hour | Checkout, multi-page pagination, app session emulation |
The window is a ceiling, not a guarantee. Real carriers move a handset between towers, drop the PDP context, or recycle the address — so a sticky session can end early. Code that assumes "1 hour means 1 hour" breaks at the worst moment; code that re-reads the current exit IP and re-authenticates when it changes does not.
Since the exit is chosen by the username, a session is just a string. Build it once, keep it stable, and rotate it deliberately:
import uuid, requests
USER, PWD = "10001-abc123", "pass456"
GW = "mobile.iplight.net:1086"
def proxy_for(region="US_California_city_LosAngeles", sticky_minutes=None):
if sticky_minutes is None:
suffix = region # rotation
elif sticky_minutes <= 5:
suffix = region + "-session" # 5 minutes
else:
suffix = region + "-session-1h" # 1 hour
return "http://%s:%s-%s@%s" % (USER, PWD, suffix, GW)
# one session per account you operate
sessions = {}
def get(account_id, url):
key = account_id
if key not in sessions:
sessions[key] = proxy_for(sticky_minutes=60)
return requests.get(url, proxies={"http": sessions[key], "https": sessions[key]}, timeout=30)One session per account, never one session shared by many accounts. Reusing a single sticky exit across ten registrations is exactly the pattern a platform is looking for — you have rebuilt the shared-IP problem that mobile was meant to solve.
Two workers pick up the same sticky username and start interleaving requests. Symptoms: unrelated pages appear in the response, or a flow suddenly asks you to log in again. Fix: the session key must include the account or task id, and the pool must hand out sessions exclusively.
The carrier rotates inside your window. Symptoms: an authenticated request returns a logged-out page. Fix: read the exit IP periodically (a cheap call to api.ipify.org through the same session) and re-authenticate when it changes.
A keep-alive connection to the gateway holds one exit for the whole run. Symptoms: 500 requests, one IP. Fix: disable connection reuse for rotation workloads, or open a new session per batch.
A typo in the location token silently falls back. Symptoms: prices in the wrong currency, a localised site in the wrong language. Fix: assert the expected country from the exit IP on the first request of every run.
No. Billing is by traffic, not by session or by IP. A sticky session and a rotating request cost the same per gigabyte — the difference is purely how the carrier routes it. That is why the decision should be made on what the target site expects, never on price.
The 1-hour window is the longest supported today. For longer continuous identity, re-establish a session and re-authenticate; the exit may change, so design the flow to tolerate it.
Bounded by sub-account concurrency rather than by a separate session quota. Each concurrent sticky session consumes one connection, so plan concurrency and session count together.
Not exclusively — carrier addresses are shared with real handsets. Sticky mode guarantees you keep the same exit, not that nobody else uses it. That sharing is precisely why mobile IPs carry good reputation.
Per new connection to the gateway. HTTP keep-alive can hold one exit across many requests, which is why rotation tests should open fresh connections.
Related: Mobile proxies · Mobile proxy in Python · Mobile setup docs · Mobile use cases · Pricing
The same 1 TB package can run rotating and sticky sessions side by side — separate sub-accounts, same quota.