Quick answer
How do I connect Python requests and Scrapy to CrawlRelay?
Point both tools at http://USERNAME:[email protected]:7777, using the CrawlRelay username and password from Connection details. In requests, pass it in proxies for http and https; in Scrapy, set it in request.meta under proxy. Add -country-de or -session-ID-ttl-10 to the username to target a country or keep one IP.
In brief
- Gateway: gw.crawlrelay.com, port 7777 for HTTP and HTTPS through CONNECT, port 7778 for SOCKS5.
- Scheme: write http:// for the proxy even when the target is https://; SOCKS5 needs the requests[socks] extra.
- Rotation: each new connection usually gets a new IP; a session part in the username keeps one IP up to 30 minutes.
- Credentials: read them from environment variables, never from the code; encode them in the URL with quote().
- Errors: 407 means the login was refused; the error list in the docs covers the others.
Which setting goes where in each tool?
One proxy URL, three ways to hand it over. The values come from the Connection details card of your plan.
| Tool | Proxy URL | Where it goes | New IP per request |
|---|---|---|---|
| requests (HTTP) | http://USER:[email protected]:7777 | proxies={"http": url, "https": url} | Plain requests.get calls, or a Session sending Connection: close |
| requests (SOCKS5) | socks5h://USER:[email protected]:7778 | Same proxies dict, after installing requests[socks] | Same as HTTP |
| Scrapy | http://USER:[email protected]:7777 | request.meta["proxy"] on each Request | New connections usually rotate; a new session ID forces it |
What do you need before writing any code?
You need three values from the CrawlRelay client area: the base username, the password and the gateway address, all on the Connection details card of your plan. Store the first two in environment variables, so they stay out of version control and out of logs.
The base username is the part before any targeting. Everything else is added to it with dashes, in the order of the format USERNAME-country-{cc}-state-{state}-city-{city}-zip-{zip}-asn-{asn}-session-{id}-ttl-{minutes}; parts you do not need are left out. Values are lower case, and a city with a space takes an underscore, as in city-new_york. Where each value appears after a purchase is shown on get your proxy credentials.
Install the libraries with pip install requests scrapy. Add the socks extra only if you plan to use port 7778.
How do you send requests through the proxy in Python?
Build the proxy URL once, then pass the same URL for both the http and https keys of the proxies argument. The https key matters most: without it, requests sends HTTPS traffic directly from your own IP. The gateway opens a CONNECT tunnel, so the TLS session still runs end to end between your script and the site.
The example below prints the exit IP twice with rotation, then twice through one sticky session. With rotation, the two answers usually differ; with the sticky username, they match unless the residential device goes offline first. It reads CRAWLRELAY_USER and CRAWLRELAY_PASSWORD from the environment.
import os
from urllib.parse import quote
import requests
USER = os.environ["CRAWLRELAY_USER"] # base username from Connection details
PASSWORD = os.environ["CRAWLRELAY_PASSWORD"]
GATEWAY = "gw.crawlrelay.com:7777"
def proxies(username):
url = "http://%s:%s@%s" % (quote(username, safe=""), quote(PASSWORD, safe=""), GATEWAY)
return {"http": url, "https": url}
rotating = proxies(USER + "-country-de")
for _ in range(2):
r = requests.get("https://ipinfo.io/json", proxies=rotating, timeout=30)
print("rotating", r.json()["ip"])
sticky = proxies(USER + "-country-de-session-job42-ttl-10")
for _ in range(2):
r = requests.get("https://ipinfo.io/json", proxies=sticky, timeout=30)
print("sticky", r.json()["ip"])
How do you use the SOCKS5 port from Python?
Install the extra with pip install "requests[socks]", then swap the scheme to socks5h and the port to 7778; the username stays the same. The h in socks5h asks the gateway to resolve the hostname at the exit, which keeps DNS lookups from leaving through your own network.
SOCKS5 is useful for tools that only speak SOCKS, or for non-HTTP protocols. For ordinary web scraping, the HTTP port 7777 is simpler and gives clearer errors, such as a 407 status instead of a closed socket.
import os
from urllib.parse import quote
import requests # pip install "requests[socks]"
user = quote(os.environ["CRAWLRELAY_USER"] + "-country-gb", safe="")
password = quote(os.environ["CRAWLRELAY_PASSWORD"], safe="")
proxy = "socks5h://%s:%[email protected]:7778" % (user, password)
r = requests.get("https://ipinfo.io/json", proxies={"http": proxy, "https": proxy}, timeout=30)
print(r.json())
How do you plug the proxy into a Scrapy spider?
Set request.meta["proxy"] on every request; Scrapy's built-in HttpProxyMiddleware reads the credentials from that URL and sends the Proxy-Authorization header for you. No extra package is needed, and the middleware is on by default.
The spider below crawls the practice site books.toscrape.com. Listing pages share one sticky session, so pagination keeps a single exit, while each book page is fetched through rotation. ROBOTSTXT_OBEY stays on and four concurrent requests per domain keep the rate polite. The full middleware version, with retries on a new IP, is in the Scrapy guide.
import os
from urllib.parse import quote
import scrapy
USER = os.environ["CRAWLRELAY_USER"]
PASSWORD = os.environ["CRAWLRELAY_PASSWORD"]
def proxy_url(country="gb", session=None, ttl=10):
username = "%s-country-%s" % (USER, country)
if session:
username += "-session-%s-ttl-%d" % (session, ttl)
return "http://%s:%[email protected]:7777" % (
quote(username, safe=""), quote(PASSWORD, safe=""))
class BooksSpider(scrapy.Spider):
name = "books"
custom_settings = {"ROBOTSTXT_OBEY": True, "CONCURRENT_REQUESTS_PER_DOMAIN": 4}
def start_requests(self):
yield scrapy.Request("https://books.toscrape.com/",
meta={"proxy": proxy_url(session="listing1")})
def parse(self, response):
for href in response.css("article.product_pod h3 a::attr(href)").getall():
yield response.follow(href, self.parse_book, meta={"proxy": proxy_url()})
next_page = response.css("li.next a::attr(href)").get()
if next_page:
yield response.follow(next_page, self.parse,
meta={"proxy": proxy_url(session="listing1")})
def parse_book(self, response):
yield {"title": response.css("h1::text").get(),
"price": response.css("p.price_color::text").get()}
Why do you sometimes keep the same IP when you expect a new one?
Connection reuse is the cause: a new IP comes with a new connection, and a connection kept open keeps its exit. The published rule is: Rotating mode: each new connection gets an IP from the pool, usually a different one; to get a new IP on every request, send one request per connection (turn off keep-alive). Both requests.Session and Scrapy keep connections open between requests to the same site, and every request on an open connection leaves through the same exit.
In requests, plain requests.get calls open a new connection each time, while a Session reuses its pool; send a Connection: close header on the Session if every call must rotate. In Scrapy, the downloader keeps a few connections per site, so consecutive requests share exits for a while. When a retry must change IP, give it a fresh session ID. The trade-offs are covered in sticky sessions and rotation.
What do the common proxy errors mean in Python?
A 407 status means the gateway refused the username or password; most other failures come from the target site, not the proxy. CrawlRelay documents 15 errors with their causes in the error reference.
- 407 Proxy Authentication Required: wrong password, a password changed with Create a new password, or an unknown targeting value.
- ProxyError or a tunnel failure: the URL scheme or the port is wrong; HTTP uses 7777, SOCKS5 uses 7778.
- SSL: WRONG_VERSION_NUMBER: the proxy URL starts with https://; it must start with http://.
- 403 or 429 from the site: the target is limiting you; slow down per domain rather than adding IPs.
Requests to blocked targets are refused by design: Banking, government and payment-portal sites, plus SMTP (email-sending) ports 25, 465 and 587.
How much traffic will a test crawl use?
According to CrawlRelay's price list, the 1 GB test plan costs $1.50 and is described as about 20,000 HTML pages, which is enough to run both scripts above many times over. Usage counts all data sent and received through the proxy (upload and download, headers included). 1 GB = 1,000,000,000 bytes. Connection attempts that fail before reaching the target are not counted.
The Statistics tab of the plan shows daily traffic and requests, so you can divide one by the other after a test and size the next plan from real numbers instead of estimates.
Frequently asked questions
Should the CrawlRelay proxy URL start with http or https?
With http://, even for https targets. CrawlRelay's port 7777 accepts plain HTTP and opens a CONNECT tunnel, inside which your TLS session runs unchanged.
Does Scrapy need a plugin to use CrawlRelay?
No. Scrapy's built-in HttpProxyMiddleware reads the credentials from request.meta["proxy"] and sends them to CrawlRelay. A custom middleware only helps to rebuild usernames on retries.
Can I use httpx or aiohttp with CrawlRelay instead of requests?
Yes. Both take the same CrawlRelay proxy URL; the Python docs page shows httpx and aiohttp versions, including asyncio concurrency per host.
How do I keep one CrawlRelay IP for a login flow?
Add -session-ID-ttl-MINUTES to the username, with a TTL between 1 and 30 minutes that outlasts the flow. CrawlRelay keeps that IP unless the device goes offline first.
Why does my script still show my own IP with CrawlRelay?
Usually the https key is missing from the proxies dict, so HTTPS requests skip the proxy. Set the same CrawlRelay URL for both http and https.
Verdict
- Use requests for scripts and checks: one proxies dict on port 7777, a session part when a flow needs one IP.
- Use Scrapy for crawls with many pages: request.meta["proxy"] is enough, and sticky sessions keep pagination on one exit.
Sources (3)
- Requests: Advanced usage, Proxies and SOCKS — Requests project (read 2026-11-13)
- Downloader middleware: HttpProxyMiddleware — Scrapy project (read 2026-11-13)
- urllib.parse.quote — Python Software Foundation (read 2026-11-13)
Get credentials and run the code
$1.50 for 1 GB, traffic that never expires, paid in crypto.