FAQ
How do I integrate a proxy into a Python scraper?
Take the provider’s endpoint, your credentials, the supported protocol and any limits. Keep the credentials in environment variables rather than in the script, then pass the proxy through a dictionary, set a timeout, and decide up front which status codes you will accept.
Then the parts that decide whether it survives contact with a real site.
- Keep concurrency modest and retry with backoff rather than immediately trying again.
- Log the status, the latency and which session or location you used. Never log the credentials.
- Validate what comes back before storing it, because a proxy returning a block page still returns a 200 sometimes.
import os
import requests
# From the environment, never hardcoded. A proxy URL contains a password,
# and a hardcoded one ends up in version control within the week.
proxy_url = os.environ["PROXY_URL"] # http://user:pass@gateway:port
proxies = {
"http": proxy_url,
"https": proxy_url,
}
# A timeout is not optional. Without one a hung connection blocks the worker
# for as long as the operating system allows, which can be minutes.
response = requests.get(
"https://example.com",
proxies=proxies,
timeout=15,
)Worth knowing
If the site offers an official API, use it instead. Every scraper is a maintenance commitment that the site can break without warning.
Other questions
What are residential proxies?How do I scrape websites without getting blocked?Can I use proxies anonymously without KYC?NullVault or Decodo, which is better for scraping?Pay as you go or subscription proxies, which should I pick?What are IPv6 proxies, and when do I need them?What is the right proxy setup for price monitoring?
These answers describe how the NullVault proxy network works in practice, across residential, ISP, mobile, datacenter and IPv6 pools.