Tutorials 6 min read

Rotating vs Sticky Proxies in Python requests and Playwright (with Working Code)

Most proxy bugs aren't about proxy quality. They're about using rotating where you needed sticky. Here's how to do both in Python and Playwright.

Most scraping bugs we see with proxies aren't about the proxy quality. They're about using the wrong session type for the job: rotating where you needed sticky, or sticky where you needed rotating. This guide shows both in Python requests and Playwright, plus a quick way to verify which one you're actually getting.

Rotating vs Sticky in One Sentence Each

  • Rotating: every request gets a new exit IP. Best for crawling lots of independent pages (listings, search results, product pages).
  • Sticky: the same exit IP for N minutes. Needed for anything with state: logins, carts, multi-step forms, paginated sessions.

If you log in on IP A and request page 2 from IP B, many sites will log you out or flag the session. That's the most common "my proxies are broken" ticket that isn't actually a proxy problem.

The Connection String

http://USERNAME:[email protected]:8080      # HTTP
socks5://USERNAME:[email protected]:1080    # SOCKS5

Targeting and session options go into the username:

  • Rotating, any country: USERNAME
  • Rotating, US exits only: USERNAME-country-US
  • Sticky for 10 minutes: USERNAME-session-abc123-time-10
  • Sticky, US, 30 minutes: USERNAME-country-US-session-abc123-time-30

abc123 is any session ID you choose. The same ID keeps the same IP until the time runs out; a new ID gets a new IP. The proxy generator in your dashboard builds these strings for you.

Python requests: Rotating

import requests

USER, PASS = "your_user", "your_pass"
proxy = f"http://{USER}-country-US:{PASS}@global.nodeproxies.xyz:8080"
proxies = {"http": proxy, "https": proxy}

for i in range(3):
    ip = requests.get("https://api.ipify.org", proxies=proxies, timeout=20).text
    print(i, ip)   # expect a different IP each time

Python requests: Sticky

import uuid, requests

USER, PASS = "your_user", "your_pass"
session_id = uuid.uuid4().hex[:8]
proxy = f"http://{USER}-session-{session_id}-time-10:{PASS}@global.nodeproxies.xyz:8080"

s = requests.Session()
s.proxies = {"http": proxy, "https": proxy}

for i in range(3):
    print(i, s.get("https://api.ipify.org", timeout=20).text)  # expect the same IP

Generate a new session_id per logical user session (per account, per cart), not per request.

Playwright: One Sticky Session per Browser Context

import uuid
from playwright.sync_api import sync_playwright

USER, PASS = "your_user", "your_pass"

with sync_playwright() as p:
    browser = p.chromium.launch()
    sid = uuid.uuid4().hex[:8]
    context = browser.new_context(proxy={
        "server": "http://global.nodeproxies.xyz:8080",
        "username": f"{USER}-country-US-session-{sid}-time-30",
        "password": PASS,
    })
    page = context.new_page()
    page.goto("https://api.ipify.org")
    print(page.inner_text("body"))
    browser.close()

One context equals one sticky identity. Need five parallel identities? Create five contexts with five different session IDs.

Quick Sanity Checks Before You Blame the Proxy

  1. Print the exit IP at the start of every job. Rotating should change; sticky shouldn't.
  2. Check the country your target sees. Geo-specific prices and search results depend on it.
  3. Measure success rate on your real target, not a test site. Log status codes for about 100 requests.
  4. Match session type to the flow: stateless pages get rotating, anything behind a login gets sticky.

Cost Tip

Use datacenter IPs for sites that don't fight bots, and residential only where you get blocked. On NodeProxies, datacenter starts at $0.42/GB and residential at $0.65/GB, dropping automatically with volume. You can test the code above with the free 100 MB residential trial on our Discord.

NodeProxies

Ready to get started?

90M+ residential, mobile & datacenter proxies. Datacenter from $0.30/GB, residential from $0.42/GB. No contracts.

Create free account