Skip to main content
Scraper API

How to Load Proxies: Configuration for Python, Selenium, and Tools [2026]

6 min read

Introduction

In the landscape of web scraping and automation in 2025, knowing how to load proxies correctly is the difference between a successful data harvest and an immediate IP ban. Loading proxies is not merely about inserting an IP address; it involves understanding protocols (HTTP vs. SOCKS), authentication methods, and rotation logic.

This guide provides a technical deep dive into loading proxies across various environments, from Python scripts to enterprise-grade load balancers.

---

Understanding Proxy Protocols

Before loading a proxy, you must understand the protocol required for your target task. Using the wrong protocol will result in connection errors.

HTTP vs. HTTPS Proxies

  • HTTP Proxies: Designed for handling web traffic. They can handle unencrypted HTTP traffic and can "tunnel" HTTPS traffic (via the CONNECT method).
  • HTTPS Proxies: This is often a misnomer in configuration fields. It usually refers to an HTTP proxy that can handle HTTPS *targets*, or a proxy that supports TLS encryption between your client and the proxy server itself.
  • SOCKS Proxies (The 2025 Standard)

    SOCKS (Socket Secure) proxies are lower-level than HTTP proxies. They are preferred in modern scraping because they handle any type of TCP traffic, not just HTTP/HTTPS.

  • SOCKS4: Handles TCP without authentication.
  • SOCKS5: Supports TCP, UDP, and authentication (Username/Password).
  • > Pro Tip: Always prefer SOCKS5 if your provider supports it. It is generally faster and more robust for scraping tasks.

    ---

    Method 1: Loading Proxies in Python

    Python is the primary language for web scraping. Here is how to load proxies into the most popular libraries.

    Basic Loading with requests

    The simplest way to load a proxy is passing a dictionary to the library.

    import requests
    

    Standard format

    proxies = { 'http': 'http://10.10.1.10:3128', 'https': 'http://10.10.1.10:1080', }

    With Authentication

    proxies_auth = { 'http': 'http://user:pass@10.10.1.10:3128', }

    response = requests.get('http://httpbin.org/ip', proxies=proxies_auth) print(response.json())

    Loading SOCKS Proxies in Python

    To load SOCKS proxies, you need the requests[socks] package.

    Install: pip install requests[socks]

    proxies_socks = { 'http': 'socks5://user:pass@host:port', 'https': 'socks5://user:pass@host:port' }

    Ensure you have pysocks installed

    r = requests.get('http://httpbin.org/ip', proxies=proxies_socks)

    Environment Variables (Global Loading)

    Instead of hardcoding proxies in every script, you can load them globally using environment variables. This is "Method 2" for system-wide proxying.

    export HTTP_PROXY="http://10.10.1.10:3128"
    

    export HTTPS_PROXY="http://10.10.1.10:1080"

    Python's requests library automatically detects these variables, requiring no code changes.

    ---

    Method 2: Loading Proxies in Selenium & Browsers

    Browser automation (RPA) requires a different approach as the network traffic is controlled by the browser engine, not the Python interpreter.

    Selenium 4 (Python)

    Loading proxies in Selenium 4 has changed significantly from version 3. You now use Options and Capabilities separately.

    from selenium import webdriver
    

    from selenium.webdriver.chrome.options import Options from selenium.webdriver.common.proxy import Proxy, ProxyType

    Define Proxy Object

    proxy = Proxy() proxy.proxy_type = ProxyType.MANUAL proxy.http_proxy = "ip_addr:port" proxy.ssl_proxy = "ip_addr:port"

    Apply to Options

    capabilities = webdriver.DesiredCapabilities.CHROME proxy.add_to_capabilities(capabilities)

    Or with Options (Preferred in Selenium 4+)

    options = Options() options.add_argument('--proxy-server=http://ip_addr:port')

    driver = webdriver.Chrome(options=options) driver.get("http://httpbin.org/ip")

    Loading Proxies with Authentication in Selenium

    Browsers do not natively support user:pass in the proxy URL (like http://user:pass@ip). You must use an extension or a background helper tool.

    Workaround: Create a background.js extension file that handles the auth prompt.

    ---

    Advanced: Loading Proxies from a List (Rotation)

    In 2025, single proxies are rarely sufficient. You need to "load" a pool of proxies and rotate them.

    Parsing a Proxy List

    Assume you have a proxies.txt file:

    192.168.1.1:8080
    

    10.0.0.1:3128 user:pass@127.0.0.1:8000

    Python Loader Implementation:

    import itertools
    

    import requests

    def load_proxy_pool(filepath): with open(filepath, 'r') as f: # Strip whitespace and filter empty lines return [line.strip() for line in f if line.strip()]

    def get_session(proxy_pool): # Create a session for persistent connections (Keep-Alive) session = requests.Session()

    # Cycle through proxies infinitely using itertools proxy_cycle = itertools.cycle(proxy_pool)

    return session, proxy_cycle

    Usage

    pool = load_proxy_pool('proxies.txt') session, cycle = get_session(pool)

    for i in range(5): proxy = next(cycle) print(f"Attempting request via: {proxy}") try: # Formatting the proxy dict proxies = {'http': f'http://{proxy}', 'https': f'http://{proxy}'} r = session.get('http://httpbin.org/ip', proxies=proxies, timeout=5) if r.status_code == 200: print("Success!") break # Stop on success except Exception as e: print(f"Proxy {proxy} failed: {e}")

    ---

    Troubleshooting Proxy Loading Issues

    1. Connection Refused / ECONNREFUSED

  • Cause: The proxy server is down, or you have the wrong port.
  • Fix: Check firewall rules (iptables/UFW) on the VPS hosting the proxy.
  • 2. 407 Proxy Authentication Required

  • Cause: Incorrect credentials or formatting.
  • Fix: Ensure the string is http://username:password@ip:port. Be careful with special characters in the password (URL encode them using urllib.parse.quote).
  • 3. SSL: CERTIFICATE_VERIFY_FAILED

  • Cause: The proxy is performing a Man-in-the-Middle (MITM) inspection (common in corporate proxies).
  • Fix: You may need to point the certifi bundle to the proxy's custom certificate, or disable SSL verification (not recommended for production).

---

Best Practices for 2025

1. Session Management: Always use requests.Session(). Loading a proxy creates a TCP handshake; reusing the session across multiple requests speeds up scraping significantly. 2. Protocol Fallback: If you load an HTTP proxy and it fails, try loading it as a SOCKS proxy if the provider supports dual-stack. 3. Geolocation: If loading proxies for localized content, verify the IP using an endpoint like /ip before sending the actual payload request. 4. Load Balancing: If using tools like Scrapy, use their built-in HttpProxyMiddleware to handle loading and retrying failed proxies automatically rather than writing manual try/except blocks.

Share: