Proxy plans now up to 15% cheaper
View pricing

Scrapy

Add a proxy to Scrapy via settings or middleware. Authenticate and rotate IPs for reliable crawling with ready-to-run code.

Integrations5 min read

This page covers Scrapy proxy setup, authentication, and IP rotation for crawls. Scrapy routes requests through a ColdProxy gateway with the built-in HttpProxyMiddleware: no extra package required. Set request.meta["proxy"] (with credentials in the URL) and Scrapy extracts the username/password into a Proxy-Authorization header for you. Below are the per-request pattern, a project-wide middleware, rotating and sticky setups, and the credential-stripping gotcha that trips up rotating-proxy code. For background, see IP whitelisting vs username/password and static vs rotating proxies.

Note

ColdProxy auto-detects HTTP, HTTPS, and SOCKS5 on every port in 30000-34999, but Scrapy has no built-in SOCKS support: its HttpProxyMiddleware speaks HTTP(S) proxies only. Use the http:// scheme for the gateway (it tunnels HTTPS target requests via CONNECT); that path covers every ColdProxy workflow in Scrapy. See Protocols for what each protocol adds.

Your ColdProxy connection details

Code
Proxy URL: http://USERNAME:PASSWORD@gw-2312.coldproxy.com:30000
Host:      gw-2312.coldproxy.com
Port:      30000     (any port in your plan's 30000-34999 allocation)

2312 is your service/package ID from the client area. Residential IPv4 (GB Based) and Residential IPv6 activate instantly after payment clears; Residential IPv4 (Unmetered) and Datacenter IPv6 start automatic setup after payment clears. Allow up to 10 minutes for those two plans and connect as soon as setup completes. See Activation and setup times, then verify with the proxy checker and my IP.

Per-request proxy via request.meta

The minimal setup: put the full proxy URL (credentials included) in request.meta["proxy"]. HttpProxyMiddleware is enabled by default, parses the credentials, and adds the Proxy-Authorization: Basic ... header automatically.

Python
import scrapy

class IpSpider(scrapy.Spider):
    name = "ip"
    PROXY = "http://USERNAME:PASSWORD@gw-2312.coldproxy.com:30000"

    def start_requests(self):
        yield scrapy.Request(
            "https://api.vipv6proxy.com/api/checker/my-ip",
            meta={"proxy": self.PROXY},
            callback=self.parse,
        )

    def parse(self, response):
        self.logger.info("Exit IP: %s", response.json()["ip"])
Warning

HttpProxyMiddleware strips the credentials out of meta["proxy"] after it builds the header (the stored value becomes the bare http://gw-...:30000). If code later sets meta["proxy"] to a different proxy URL without credentials, the middleware drops the Proxy-Authorization header and auth is lost. For anything beyond a single hop, set the header yourself (next section) or re-supply the full credentialed URL each time.

Project-wide Scrapy proxy middleware (stable auth for redirects and retries)

For production spiders, set the proxy and a stable Proxy-Authorization header in a small downloader middleware. Setting the header explicitly survives redirects and retries.

Python
# middlewares.py
import base64

class ColdProxyMiddleware:
    HOST = "gw-2312.coldproxy.com:30000"
    USER = "USERNAME"
    PWD = "PASSWORD"

    def process_request(self, request, spider):
        request.meta["proxy"] = f"http://{self.HOST}"
        token = base64.b64encode(f"{self.USER}:{self.PWD}".encode()).decode()
        request.headers["Proxy-Authorization"] = f"Basic {token}"
Python
# settings.py
DOWNLOADER_MIDDLEWARES = {
    "myproject.middlewares.ColdProxyMiddleware": 610,
    # keep below the built-in HttpProxyMiddleware (default 750)
}
Tip

You can also build the header with w3lib.http.basic_auth_header("USERNAME", "PASSWORD") if w3lib is already in your environment (it ships with Scrapy). Both produce the same Basic token.

Geo-targeting and sticky sessions through the username

ColdProxy encodes geo and session controls as tags inside the username, grammar user-key-value-key-value... (full reference: Username tag scheme). Rotation is the default; a sticky IP needs both a session id and a duration together. The tagged username goes in the proxy URL (or the middleware's USER). See rotating and sticky proxies and geo-targeting with proxies.

Python
# Rotating, United States — new IP per request
PROXY = "http://user-country-us:PASSWORD@gw-2312.coldproxy.com:30000"

# Sticky 10 minutes, United States — same IP while the session holds
PROXY = "http://user-country-us-session-481516-time-10m:PASSWORD@gw-2312.coldproxy.com:30000"
Warning

The exact tag prefixes (e.g. country, state, city, session, time, identifier) are set per product by ColdProxy; confirm the prefixes for your plan in your client area. Sticky limits differ by product: Residential IPv4 supports 5s-24h; Residential IPv6 and Datacenter IPv6 support 5s-FOREVER.

Scrapy rotating proxy sessions per request

To rotate sticky identities across a crawl, vary the session tag in the username per request. Each distinct session id maps to its own sticky IP for the chosen duration.

Python
import scrapy

class RotateSpider(scrapy.Spider):
    name = "rotate"
    TEMPLATE = "http://user-country-us-session-{sid}-time-10m:PASSWORD@gw-2312.coldproxy.com:30000"

    def start_requests(self):
        for i in range(5):
            proxy = self.TEMPLATE.format(sid=481516 + i)  # session IDs are numeric
            yield scrapy.Request(
                "https://api.vipv6proxy.com/api/checker/my-ip",
                meta={"proxy": proxy},
                dont_filter=True,
                callback=self.parse,
            )

    def parse(self, response):
        self.logger.info("Exit IP: %s", response.json()["ip"])
Note

If you use scrapy-rotating-proxies, requests with meta["proxy"] already set are skipped by that middleware, and its dead/alive bookkeeping can mismatch when HttpProxyMiddleware strips credentials from the stored proxy value. With a single ColdProxy gateway you usually do not need it; rotate via the username session tag instead.

IP whitelisting (no credentials in code)

ColdProxy supports IP authentication: whitelist up to 50 IPs in the client area or via the plan API, and use the gateway with no user:pass at all.

Python
yield scrapy.Request(
    "https://api.vipv6proxy.com/api/checker/my-ip",
    meta={"proxy": "http://gw-2312.coldproxy.com:30000"},
)
Note

With IP-auth and no SuperPorts, the gateway defaults to Worldwide geo. Bind country/state/city to a port range with SuperPorts to geo-target as an IP-auth user, or authenticate with user:pass and use username tags.

Useful settings

Keep concurrency and rate sensible so you reduce IP blocks during public web data collection without overloading targets. See proxy error codes 407/403/429/502/504 for what the gateway returns under pressure.

Python
# settings.py
CONCURRENT_REQUESTS = 16
DOWNLOAD_DELAY = 0.5
RETRY_ENABLED = True
RETRY_TIMES = 3
AUTOTHROTTLE_ENABLED = True
Warning

A 407 Proxy Authentication Required means the Proxy-Authorization header did not reach the gateway; confirm the credentials, and on redirects/retries use the explicit-header middleware above rather than relying on credentials in meta["proxy"].

Verify and troubleshoot

  • Log response.text from https://api.vipv6proxy.com/api/checker/my-ip, or run the proxy checker, to confirm the exit IP and location.
  • Connection errors immediately after ordering can have several causes. Check the service status and connection settings. If you bought Residential IPv4 (Unmetered) or Datacenter IPv6, automatic setup may still be running for up to 10 minutes after payment clears; see Activation and setup times.
  • For IPv6 plans, many sites are IPv4-only (no AAAA record) and will fail over IPv6; check the target with the IPv6 checker before buying. Confirmed IPv6-ready platforms include Google, YouTube, Facebook, Instagram, Bing, and LinkedIn.

Ready to provision? Compare plans on pricing or browse the proxy products.

Need a tailored proxy plan for a large project?

Need a different speed or traffic allowance? Contact us through the channels on our website so we can assess whether a custom plan is possible.

Contact Our Sales TeamTelegram & ticket support · English and Arabic