insocks
Back to blog. Article language: BN EN ES FR HI ID PT RU UR VI ZH

Setting up proxies in Scrapy

A proxy in Scrapy routes requests through a controlled endpoint to collect public data reliably. A safe Scrapy proxy setup helps with localization, load distribution, monitoring, and stable crawling. In the USA, use proxies only for lawful public workflows respecting robots.txt, terms, and rate limits.

Why Scrapy projects need proxies

Scrapy projects need proxies when one direct connection is too limited for reliable public data collection. A planned Scrapy proxy workflow helps teams reduce connection failures, compare regional pages, and keep tests measurable.

✅ Legal scenarios:

  • Public product page monitoring
  • QA for regional content
  • Uptime and availability checks
  • Internal data validation

Which proxy type is best for Scrapy

The best proxy type depends on stability, session length, price, and region. For long public checks, a Scrapy rotating proxy plan can spread requests across approved routes without turning automation into spam.

TypeStabilityBest for
ResidentialHighLocal public pages
MobileMediumMobile web checks
ISPHighLong sessions
DatacenterMediumInternal QA

What you need before you start

Before setup, prepare Scrapy, route details, credentials, and a test URL. A Scrapy proxy middleware plan also needs clear ownership, safe storage, and logs.

✅ Checklist:

  • Scrapy project
  • IP and port
  • Login and password
  • Test URL
  • Rate limits
  • Error logging

How to set a single proxy in Scrapy step by step

One route is the easiest first test. In this setup, Scrapy proxy access is passed through request metadata and handled by the built-in middleware.

  • Step 1. Enable the proxy middleware.
  • Step 2. Add the route to request meta.
  • Step 3. Run one spider.
  • Step 4. Check status code.

class DemoSpider(scrapy.Spider):

name = "demo"

start_urls = ["https://example.com"]

def start_requests(self):

for url in self.start_urls:

yield scrapy.Request(

url,

meta={"proxy": "http://user:pass@host:port"}

)

Use httpproxymiddleware for approved workflows and keep secrets outside code.

How to add proxy authentication

Authentication confirms that your script may use the route. For paid endpoints, Scrapy proxy middleware should protect login data and support proxy authentication without exposing passwords in repositories.

import base64

token = base64.b64encode(b"user:pass").decode()

headers = {"Proxy-Authorization": f"Basic {token}"}

yield scrapy.Request(

"https://example.com",

headers=headers,

meta={"proxy": "http://host:port"}

)

Store credentials in environment variables. Rotate passwords after staff changes.

How to rotate proxies with middleware

Rotation helps distribute requests across approved endpoints. A careful Scrapy rotating proxy workflow changes routes between requests while keeping delays, logs, and limits clear.

  • Step 1. Store approved pool.
  • Step 2. Pick one route for each request.
  • Step 3. Attach it in middleware.
  • Step 4. Log route ID.

class ProxyMiddleware:

def __init__(self, routes):

self.routes = routes

@classmethod

def from_crawler(cls, crawler):

return cls(crawler.settings.getlist("PROXY_POOL"))

def process_request(self, request, spider):

request.meta["proxy"] = random.choice(self.routes)

A rotating proxy middleware should never replace rate control or compliance review.

How to tune DOWNLOAD_DELAY and AUTOTHROTTLE

Delay settings keep crawls stable. A Scrapy rotating proxy setup should still use download delay and autothrottle to avoid sudden traffic spikes.

DOWNLOAD_DELAY = 2

AUTOTHROTTLE_ENABLED = True

AUTOTHROTTLE_START_DELAY = 1

AUTOTHROTTLE_MAX_DELAY = 10

CONCURRENT_REQUESTS = 8

Track response time before changing settings.

How to handle retries and bans

Retries should recover from temporary network issues, not force repeated access. A Scrapy proxy setup should use modest retry limits, clear pauses, and logs that show why a request failed.

💡 Set RETRY_TIMES after testing normal error rates.

✅ Do:

  • Use small batches
  • Respect robots.txt
  • Monitor status codes

❌ Don't:

  • Retry forever
  • Ignore 403 or 429 patterns
  • Overload public pages

How to verify proxies work in Scrapy

Verification confirms that requests go through the expected endpoint before real collection starts. A tested Scrapy proxy middleware flow should show IP, region, response code, and timing.

What to checkExpected result
IP addressSelected endpoint
RegionPlanned area
Status codeNormal response
SpeedStable timing

Common Scrapy proxy errors and fixes

Most failures come from wrong credentials, dead routes, ports, or fast settings. If Scrapy proxy tests fail, check one variable at a time instead of changing the whole spider.

❌ Common issues:

  • Connection refused
  • Timeout
  • Authentication failure
  • Too many retries
ErrorCauseFix
RefusedWrong hostRecopy route
TimeoutSlow endpointTest another route
Auth failedBad loginRefresh credentials
429Too fastIncrease delay

Ethical scraping notes (USA)

Scrapy can be used responsibly for public data, QA, monitoring, and research. A lawful Scrapy proxy workflow respects robots.txt, site terms, public data boundaries, and rate limits.

For U.S. use, document task purpose, source, owner, and retention. Proxies should support compliance, not hide abusive behavior.

Choosing a reliable proxy for Scrapy

A good provider offers stable routes, clear regions, support, and pricing in $. For advanced projects, a Scrapy SOCKS5 proxy may be useful when the provider and connector support it.

FeatureBenefit
Stable routesFewer failures
Clear regionsBetter tests
SupportFaster fixes
PricingBudget control

Try a demo for one spider, buy proxies after validation, or register for full access.

Key takeaways

TL;DR: proxies help Scrapy run lawful public workflows through controlled routes. A Scrapy proxy should match the target, rate limits, and logs. Rotation works best with delays and monitoring. Authentication must be stored safely.

Frequently asked questions

How do I set a proxy in Scrapy?

Add the route to request metadata and enable the proper middleware.

How do I rotate proxies in Scrapy?

Use custom middleware that selects one approved route for each request.

Does Scrapy support SOCKS5 proxies?

Yes, with the right connector and provider support.

How do I add proxy authentication in Scrapy?

Pass credentials securely through headers, route format, or environment variables.

How do I avoid bans while scraping with Scrapy?

Respect robots.txt, site terms, rate limits, and data boundaries.

2026-07-15