Scrapy rotating proxies: gateway or custom middleware
Choose a gateway or owned middleware for a Scrapy production job.

Scrapy rotating proxies can mean a provider-managed gateway or a list that your own middleware selects from. Decide who owns that selection before adding code. Two mechanisms trying to control the same route can create failures that look like a network problem.
Choose one owner for exit selection
A gateway gives your spider a connection endpoint whose service chooses an exit under its documented rules. A locally managed list gives your application responsibility for choosing entries and deciding when they are usable. The right option depends on the control you need and the operating work you can support.
Write down who handles selection, authentication, failure classification and replacement. A middleware package does not establish a right to use a target or a guarantee that every listed address works. Verify both the collection scope and the connection contract.
Start with one explicit request
Scrapy's proxy support uses request metadata with its HTTP proxy middleware. The proxy setting is separate from the destination URL. Check the actual download handler you use, because third-party handlers can have different capabilities.
The function below creates a request for a permitted target. It assigns an existing proxy URL; it does not implement rotation or call a proxy-management API.
import scrapy
def proxied_request(url, proxy_url):
if not proxy_url:
raise ValueError("an assigned proxy URL is required")
return scrapy.Request(
url,
meta={"proxy": proxy_url, "download_timeout": 15},
dont_filter=False,
)
Load the URL from private configuration and keep credentials out of logs. This request-level timeout is not a complete spider deadline. The caller still needs limits on job duration, retries and queued work.
Review middleware ordering
Inspect enabled downloader middleware and its order before introducing another component. Proxy authentication, retries and custom request changes can interact. A configuration that works with one handler is not automatically equivalent under another.
Use the supported interface from the Scrapy version you deploy. Test the final request seen by the downloader, not just the value assigned earlier in your spider. Keep an unexpected proxy override or missing authentication as a visible configuration failure.
If you own a proxy list, define selection and health state explicitly. A connection failure and a target response should not automatically produce the same replacement action. Stop bounded failures for investigation rather than endlessly cycling through entries.
Treat a sequence as a sequence
Independent page requests and related browsing steps can need different route behavior. Cookies, connection reuse and service-side session options are separate concerns. Define which context must survive across the requests that belong together.
Do not assume that assigning the same hostname preserves an exit, or that a new request always selects a new address. Verify the gateway's documented selection trigger and account-specific session behavior. Keep the existing Scrapy setup guide as your first-connection reference.
Test the routing boundary
Use an owned fixture server and a local proxy fixture to confirm where the request goes and which authentication path is used. Include a success, an authentication rejection and a transport failure. Keep the fixture credentials visibly separate from real account values.
Then validate the returned records. An HTTP response can contain the wrong page or an incomplete template. Keep request success, parser success and accepted data as separate outcomes, with the record contract version attached.
Operate the smallest useful configuration
Prefer one clear routing mechanism over several overlapping packages. Record configuration versions and failure reasons so that a later change can be traced. Increase concurrency only within the target's permitted access and the service limits you verified.
Compare the current residential proxy contract with the spider's needs, then run a small permitted collection. A useful pilot establishes the connection and record behavior you intend to operate, not merely that the spider started.
