← Back to Blog

Parsing with Authorization: 4 Effective Methods for Saving Cookies and Sessions When Changing IP

We analyze 4 proven methods for maintaining an authorized session when the IP address changes during parsing — with Python code and an examination of common mistakes.

📅October 19, 2026

If the parser operates under an authenticated account, changing the IP almost always means an instant logout, captcha, or session ban. The platform detects a mismatch in the connection "fingerprint" and the dropped session — and resets the cookies. In this article, we will explore 4 proven schemes that allow changing the IP while maintaining authorization, plus working code in Python.

Why Does the Session Drop When Changing IP

An authenticated session is not just a cookie with a session_id. Modern platforms (marketplaces, social networks, banking cabinets) bind the session to a whole set of parameters: IP address, User-Agent, TLS fingerprint, geolocation by IP, and sometimes to the Canvas/WebGL fingerprint of the browser. As soon as one of these parameters changes abruptly — for example, the IP jumps from a Moscow data center to an IP from another country — the anti-fraud system considers this suspicious behavior and resets the session, requiring re-login or showing a captcha.

This is especially critical for tasks where parsing is done from an authenticated account: collecting prices on Wildberries through the seller's personal account, monitoring competitors on Ozon with authentication, parsing closed sections of Avito, collecting data from Instagram or VK via API with a token. In each of these cases, the combination of "account + IP + cookies" must remain stable throughout the session, rather than changing with each request, as is often done in regular parsing without authentication.

Hence, the main rule emerges: IP rotation during authenticated parsing must be controlled, not random. Below are four schemes that solve this problem with varying balances of complexity and reliability.

Scheme 1: Sticky Sessions (Binding IP to Account)

The simplest and most reliable scheme is to bind the same IP to one account or session for the entire duration of the operation (from several minutes to several hours), and change the IP only when the session is naturally ending (logout, token expiration, scheduled account change).

Technically, this is implemented through a sticky port at the proxy provider: you receive one endpoint that maintains the same outgoing IP for a specified time (usually from 1 to 30 minutes, sometimes up to several hours), after which the IP changes automatically. For tasks with authentication, the best fit is residential proxies — they provide real IPs from home providers that are not blacklisted by data centers and appear as regular users, which is critical for banking cabinets, personal accounts of marketplaces, and social networks.

The rule is simple: one account = one sticky IP for the entire lifecycle of the session. If you need to parse 50 accounts simultaneously — you set up 50 sticky sessions with different IPs, each working with its own set of cookies and not overlapping with others. This is the same principle used by SMM specialists in anti-detect browsers like Dolphin Anty or AdsPower when managing dozens of client accounts: one browser profile = one permanent IP = its own set of cookies, which does not mix with others.

If the task requires IP rotation (for example, to avoid hitting the rate limit of one session), but at the same time, you need to maintain several parallel authenticated states — the "pair pool" scheme is applied. The idea: you log in N times under different credentials (or from different starting IPs), saving for each session the combination cookies + IP + User-Agent, and for each subsequent request, you use exactly the pair with which the session was originally created.

In practice, this looks like this: in a database or in Redis, there is a table of the form "session id → cookies → proxy IP → User-Agent → last used time". Before each request, the parser takes a free pair from the pool, makes the request through the bound IP, updates the cookies from the response, and puts them back in the same record. If the session has expired (the server returned a redirect to login) — the pair is marked as invalid, removed from the pool, and a new one is created through re-login.

This scheme scales well horizontally: the more pairs of "cookies + IP" in the pool, the higher the overall throughput of the parser without the risk of bans. For this task, it is convenient to use data center proxies where speed is more important than anonymity — for example, when parsing open catalogs after authentication, when the platform does not aggressively monitor the fingerprint, and the bottleneck becomes the speed of catalog traversal.

Scheme 3: Fingerprint Binding via Anti-Detect Approach

The third scheme is needed when the platform checks not only the IP and cookies but also a full browser fingerprint: Canvas, WebGL, fonts, timezone, system language, screen resolution. This is typical for social networks (Instagram, TikTok, VK) and some marketplaces with advanced anti-fraud measures. In this case, the combination needs to be expanded to "IP + cookies + fingerprint" and stored as a whole — otherwise, even with the correct IP and valid cookies, the session will still drop due to a mismatch in the browser fingerprint.

In practice, this is solved through headless browsers with managed fingerprints (Playwright, Puppeteer with stealth plugin) or through anti-detect browsers like Dolphin Anty, Multilogin, GoLogin, or Octo Browser, where each profile is assigned its own set of fingerprint parameters, its own permanent IP through built-in proxy integration, and its own cookie storage. The profile logs in once, and then just restarts with the same parameters — the session continues to exist because the platform sees the same "device" on the same IP.

For parsing social networks and mobile applications via API, at this stage, it is common to switch to mobile proxies — operator IPs with CGNAT are less likely to raise suspicion among systems that expect traffic specifically from mobile networks, and combining IP with the required fingerprint provides the best session stability.

Scheme 4: Controlled Re-Authentication

The fourth scheme is not to try to maintain one session forever, but to embed logic for scheduled re-authentication into the parser when changing IP. This is the most labor-intensive but also the most fault-tolerant option: instead of transferring old cookies to the new IP (which almost always leads to a ban), the parser initiates a new login when the IP changes — it enters the login/password (or uses a refresh token), receives fresh cookies under the new IP, and continues working from a clean slate.

This scheme is mandatory where the API supports OAuth2 with refresh tokens (many marketplaces and advertising cabinets, such as Google Ads API, TikTok Ads API): when changing the IP, you simply exchange the refresh token for a new access token, without needing to re-enter the password. If there is no refresh token — you have to emulate a full login flow: obtain a CSRF token from the login page, send the login/password, pass any captcha or 2FA, and save the new cookies.

The downside of this scheme is that the risk of frequent logins may itself look suspicious and provoke account blocking, so it is usually combined with scheme 1: the IP changes rarely and only synchronously with scheduled re-authentication, not with every request.

Comparison of 4 Schemes

Scheme Complexity Reliability When to Apply
Sticky Sessions Low High 1 account — 1 IP, small volumes
Cookie Pool + IP Medium Medium-High Mass parsing with multiple accounts
Fingerprint Binding High High Social networks, advanced anti-fraud
Re-Authentication High Very High APIs with refresh tokens, frequent IP rotation

Code: Session + Sticky Proxy in Python

Below is a basic example using requests.Session, which saves cookies and works through the same sticky proxy throughout the session. The session automatically stores cookies, and the IP binding is achieved through the sticky port of the proxy provider, which returns the same outgoing IP for all requests within the specified time window.

import requests

# sticky port holds the same IP while the session is alive
PROXY = {
    "http": "http://login:[email protected]:8000",
    "https": "http://login:[email protected]:8000",
}

session = requests.Session()
session.proxies.update(PROXY)
session.headers.update({
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/124.0.0.0 Safari/537.36"
})

# login — cookies will be saved in session.cookies automatically
login_payload = {"login": "[email protected]", "password": "secret"}
resp = session.post("https://example.com/login", data=login_payload)
assert resp.status_code == 200

# subsequent requests go with the same cookies and the same IP
page = session.get("https://example.com/cabinet/orders")
print(page.status_code, len(page.text))

For the scheme with the cookie + IP pair pool, it is convenient to store the state in Redis — this allows scaling the parser across multiple workers without session overlap:

import json
import redis
import requests

r = redis.Redis(host="localhost", port=6379, db=0)

def get_session_pair(account_id):
    raw = r.get(f"session:{account_id}")
    if raw:
        data = json.loads(raw)
        session = requests.Session()
        session.cookies.update(data["cookies"])
        session.proxies.update({"http": data["proxy"], "https": data["proxy"]})
        return session
    return None

def save_session_pair(account_id, session, proxy_url):
    data = {
        "cookies": session.cookies.get_dict(),
        "proxy": proxy_url,
    }
    r.set(f"session:{account_id}", json.dumps(data), ex=3600)

For the fingerprint binding option via Playwright, it is sufficient to log in once and save the storage_state — it includes not only cookies but also localStorage/sessionStorage, which is critical for SPA sites of marketplaces and social networks:

from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.launch(proxy={"server": "http://gate.proxycove.com:8000",
                                        "username": "login", "password": "password"})
    context = browser.new_context()
    page = context.new_page()
    page.goto("https://example.com/login")
    page.fill("#login", "[email protected]")
    page.fill("#password", "secret")
    page.click("#submit")
    page.wait_for_selector("#cabinet")

    context.storage_state(path="session_state.json")  # save the session entirely
    browser.close()

# on the next run — the same IP + the same session
with sync_playwright() as p:
    browser = p.chromium.launch(proxy={"server": "http://gate.proxycove.com:8000",
                                        "username": "login", "password": "password"})
    context = browser.new_context(storage_state="session_state.json")
    page = context.new_page()
    page.goto("https://example.com/cabinet")

Common Mistakes

1. IP rotation on every request within one authenticated session. This is the main reason for instant bans — the system sees that one session_id is used from dozens of different IPs within a minute, and blocks it as a clear sign of automation.

2. Saving only session_id without User-Agent and other headers. If cookies were obtained with one User-Agent, but are used with another — this is also a trigger for anti-fraud, even if the IP has not changed.

3. Ignoring the geolocation of the IP. If the account logged in from Moscow, and the next request comes from an IP of another country — the session will almost always be reset, regardless of the validity of the cookies.

4. Failure to handle expired sessions. The parser must be able to distinguish "the server returned the login page" from "the server returned the required data" and automatically initiate re-authentication, rather than crashing with an error.

5. Using the same proxy pool for different accounts without binding. If two different accounts accidentally receive the same outgoing IP, the platform may link them together — this is especially dangerous for SMM agencies managing dozens of client accounts simultaneously.

Checklist Before Launching the Authenticated Parser

  • A scheme has been chosen that corresponds to the level of protection of the platform (sticky / pool / fingerprint / re-authentication)
  • Each account is assigned a permanent IP for the entire session lifespan
  • Cookies and session_id are saved together with IP, User-Agent, and headers, not separately
  • Validation of the session is implemented before each important request
  • Automatic re-authentication is set up upon detecting a dropped session
  • Proxies are selected according to the type of platform: residential for banking cabinets and e-commerce, mobile for social networks, data center for fast parsing of open sections
  • All IP changes and re-authentication moments are logged for ban analysis

Conclusion

The main takeaway is simple: when parsing with authentication, the IP and session must change synchronously, not independently of each other. The most reliable start is the sticky session scheme, where one account is tied to one IP for the entire operation period. For mass parsing under multiple accounts, the cookie + IP pair pool will work, for social networks with advanced anti-fraud — fingerprint binding via anti-detect browser, and for APIs with tokens — scheduled re-authentication when changing IP.

If you are just setting up an authenticated parser for marketplaces or personal accounts, start with residential proxies with a sticky port — they provide a stable IP for the required time and minimal risk of session blockage. For parsing social networks through authenticated APIs, it is better to consider mobile IPs, and for high-speed traversal of open catalogs after login — data center proxies, which are described above in the text.