Not the error messages the vendor docs imagine. The ones that show up between 1am and 4am.
Every item below has the same shape: symptom, what it actually means, and the smallest fix. Code is requests unless stated otherwise; httpx and Playwright notes are inline where behaviour differs.
1. 407 Proxy Authentication Required on a proxy that demonstrably works
Symptom. The vendor's curl example passes. Your Python script gets 407. Same credentials, same host, same port.
What it means. Almost always one of two things: the password contains a character your shell swallowed when it was exported, or you built the URL by concatenation and the credentials contain @ or :.
Fix. Never string-build the proxy URL by hand. Percent-encode, or let the library do it:
from urllib.parse import quote
user = quote(USER, safe="")
pwd = quote(PWD, safe="")
proxy = "http://%s:%s@%s:%s" % (user, pwd, HOST, PORT)
r = requests.get("https://api.ipify.org", proxies={"http": proxy, "https": proxy}, timeout=15)
print(r.text)
If it still 407s, print repr(os.environ.get("PROXY_PWD")). Trailing newline from a .env file is the single most common cause and it is invisible in every log.
2. https requests work, http ones leak your real IP
Symptom. https:// targets go through the proxy. http:// targets return your own IP.
What it means. requests keys the proxies dict by scheme. Passing only {"https": ...} is enough to look correct in testing, because you only tested against HTTPS targets.
Fix. Always set both keys, as in the snippet above. Then verify with an HTTP (not HTTPS) echo endpoint:
for scheme in ("http", "https"):
r = requests.get(scheme + "://api.ipify.org", proxies={"http": proxy, "https": proxy}, timeout=15)
assert r.text.strip() != MY_REAL_IP
httpx differs here: it takes a single proxy= for both schemes since 0.26, and proxies= is deprecated. If you migrated and quietly lost HTTP coverage, this is why.
3. SSLError / ProxyError only on some requests
Symptom. Intermittent ProxyError: Cannot connect to proxy, or TLS errors that appear under load and disappear on retry.
What it means. Usually connection pool exhaustion against the gateway, not a bad proxy. Mobile gateways hold a bounded number of concurrent connections per account, and requests will happily open more sockets than that if your thread pool is large.
Fix. Bound the pool and make the failure loud instead of silent:
from requests.adapters import HTTPAdapter
s = requests.Session()
adapter = HTTPAdapter(pool_connections=20, pool_maxsize=20, max_retries=0)
s.mount("http://", adapter)
s.mount("https://", adapter)
Set max_retries=0 deliberately. Retrying a connection error inside the adapter means you cannot tell a gateway limit from a dead exit, and you lose the ability to rotate on failure. Retry at the layer where you can also change the exit.
For httpx, the equivalent is limits=httpx.Limits(max_connections=20, max_keepalive_connections=0) — zero keep-alive is important for rotating workloads, see item 5.
4. Rotation that does not rotate
Symptom. You send 500 requests through a "rotating" endpoint. The target logs one IP. Or your own check finds 3 distinct IPs across 500 requests.
What it means. HTTP keep-alive. One TCP connection carries dozens of requests, and the exit is bound to the connection, not the request. The proxy is rotating correctly; your client is pinning the exit.
Fix. Break the connection per request, or per batch:
# per request, simplest
s = requests.Session()
s.headers["Connection"] = "close"
# or per batch: rebuild the session every N calls
if i % 20 == 0:
s.close()
s = requests.Session()
Verify by counting, not by trusting:
ips = set()
for _ in range(100):
ips.add(requests.get("https://api.ipify.org", proxies=P, timeout=15).text.strip())
print(len(ips)) # expect ~80+ for a rotating endpoint
If you get 1, the rotation is being defeated client-side. If you get 100 but the target still blocks you, the rotation works and the problem is elsewhere.
In Playwright the same trap exists at a different layer: browser.new_context(proxy=...) pins the exit to the browser, not the request. To rotate you must recreate the context, which means recreating storage state — plan for that rather than discovering it in production.
5. Sticky session returns a different IP mid-flow
Symptom. A logged-in sequence starts returning a logged-out page. Or prices switch currency halfway through a crawl.
What it means. Either the sticky window expired, or the carrier moved the handset, or your session token was mistyped and silently fell back to a default region. The proxy is behaving as designed; your code assumed a guarantee that was never given.
Fix. Assert the exit at the start of every business action, not on a timer:
def assert_exit(s, expected_ip):
ip = s.get("https://api.ipify.org", timeout=10).text.strip()
if ip != expected_ip:
raise ExitChanged("expected %s got %s" % (expected_ip, ip))
Cost is one ~50-byte request. Benefit is that a silent failure becomes an explicit exception you can act on — re-authenticate, or move the task to a fresh session.
Also assert region on the first request of every run: fetch the exit IP, resolve its country, compare with what you asked for. Region tokens that are slightly wrong usually do not error, they fall back.
6. Works in the browser, 403 in Python, same proxy
Symptom. Paste the proxy into a browser extension, the page loads. Same credentials in requests, you get 403 or a challenge page.
What it means. The proxy is fine. Your TLS ClientHello, HTTP/2 settings, and header order differ from Chrome's, and the target fingerprints the client. This is the fourth layer of anti-bot detection and it is the one that makes people buy a more expensive proxy that also does not work.
Fix, in order of cost:
- Match the surface:
User-Agent,Accept,Accept-Language,Accept-Encoding, and header order consistent with a real browser. - Use a client that mimics the TLS stack:
curl_cffiwithimpersonate="chrome"handles most targets that fingerprint TLS. - Only then reach for a real browser. Playwright with a persistent context and realistic locale/timezone is the honest last step, and it is expensive per page.
What not to do: install a stealth plugin and assume it solved it. Stealth patches address a subset of JS-visible signals and change nothing about the TLS handshake.
A minimal harness worth keeping
Most of the above collapses into one small utility file you write once:
class MobileClient:
def __init__(self, user, pwd, host, port, sticky_id=None):
self.user = user if not sticky_id else "%s-%s" % (user, sticky_id)
self.proxy = "http://%s:%s@%s:%s" % (self.user, quote(pwd, safe=""), host, port)
def session(self):
s = requests.Session()
s.proxies = {"http": self.proxy, "https": self.proxy}
s.headers.update(BROWSER_HEADERS)
return s
def rotate(self):
s = self.session()
s.headers["Connection"] = "close"
return s
Then wrap every call with a single decorator that: checks the exit IP, retries once on connection error with a fresh session, and records the exit in your logs. Two hours of work; it removes the entire class of "is it the proxy or my code" evenings.
The one-line summary
If a mobile proxy misbehaves in Python, the cause is in this order: credentials encoding, missing scheme key, connection pool, keep-alive defeating rotation, silent region fallback, client fingerprint. Check them in that order and you will skip most of the debugging.
IPLight's mobile pool supports rotating and 5-minute / 1-hour sticky sessions on the same traffic quota, HTTP and SOCKS5, with country and city-level targeting. The runnable examples for requests, httpx, Selenium and Playwright are in Mobile proxy in Python.
Top comments (0)