By GlobalProxyIP Editorial Team

Proxy-enabled data collection in Python needs a routing check and a data contract. A request can take the intended route while returning an unexpected page, incomplete fields, or repeated records.

Start by defining the authorized target, required fields, record identity, location context, and completion window. Public visibility does not itself authorize every collection method or subsequent data use.

Choose a route that matches the task

Independent requests and source-bound workflows have different persistence requirements. HTTP support, residential sourcing, and sticky behavior answer different questions and should not be treated as interchangeable product categories.

For an eligible overseas residential use case, Gleam's public guide provides generated location/session settings and gateway configuration. Its service and target restrictions still apply, including unavailability to users in Mainland China and restrictions on government, financial, and social media targets.

Build a small response-contract check

Use Python 3 and requests==2.34.2. Set an HTTP username/password endpoint with PROXY_HOST and PROXY_PORT. Set DATA_URL to your controlled endpoint, which accepts page and returns an items list with nonempty string IDs. Adapt real targets from their actual documentation rather than assuming this schema.

import os, json, time
from pathlib import Path
from getpass import getpass
from urllib.parse import quote
import requests

user, password = input("Proxy username: "), getpass("Proxy password: ") proxy = (f"http://{quote(user, safe='')}:{quote(password, safe='')}" f"@{os.environ['PROXY_HOST']}:{int(os.environ['PROXY_PORT'])}") proxies = {"http": proxy, "https": proxy} seen = set() # Three pages and a two-second pause are teaching values, not target permission. with requests.Session() as session, Path("records.jsonl").open("w", encoding="utf-8") as out: session.trust_env = False for page in range(1, 4): with session.get(os.environ["DATA_URL"], params={"page": page}, proxies=proxies, timeout=(5, 20), allow_redirects=False) as response: if response.status_code in {403, 429}: raise RuntimeError("Stop and review access or rate limits") response.raise_for_status() if not 200 <= response.status_code < 300: raise ValueError("Unexpected redirect") if "application/json" not in response.headers.get("Content-Type", "").lower(): raise ValueError("Expected a JSON response") payload = response.json() if not isinstance(payload, dict) or not isinstance(payload.get("items"), list): raise ValueError("Expected an items array") for item in payload["items"]: if not isinstance(item, dict) or not isinstance(item.get("id"), str) or not item["id"]: raise ValueError("Expected a nonempty string id") if item["id"] not in seen: out.write(json.dumps(item, ensure_ascii=False) + "\n") seen.add(item["id"]) if page < 3: time.sleep(2) print("unique_records", len(seen))

The script stops on refusals and rate limits, checks status and JSON structure, and deduplicates IDs within one run. It writes a new records.jsonl, overwriting an existing file; use a dedicated directory. It has no complete pagination termination logic or durable checkpoint.

Three pages and a two-second pause are teaching settings, not a general traffic allowance. Environment settings are isolated; supply an approved CA path explicitly if needed.

Keep three denominators

Request attempts include retries. Logical tasks represent intended work units. Unique valid records represent saved output after applicable validation and deduplication. One successful retry does not create another logical task or another unique record.

Without an expected record set, do not claim complete coverage from the number collected. Instead report observed output, field failures, pagination checks, and the unverified scope.

Diagnose before scaling

A content-type failure may indicate a prompt page or changed response. Missing records may come from pagination, a time window, location differences, parsing, or storage. A proxy connection error is a different layer. Increasing pool size cannot repair a wrong cursor.

Before adding concurrency, test against a known controlled dataset containing duplicates, empty pages, and missing fields. Simulate interruption and verify the saved set. Scaling should preserve the same permission, rate, identity, and data-quality rules rather than replacing them with an HTTP success percentage.

Frequently asked questions

Does status 200 mean the record is valid?

No. Validate content type, structure, fields, and task-specific meaning.

Is decoded body size the billable proxy traffic?

Not necessarily. Compression, headers, direction, failures, and provider accounting can differ.

Should 429 cause immediate exit rotation?

No. Stop or defer according to the target policy, including applicable Retry-After guidance; rotation is not a permission mechanism.

Related reading

Sources

Sources reviewed on November 20, 2026.