Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use a proxy in Python Requests by passing a proxies mapping whose keys match the destination schemes, for example {"http": "http://proxy.example:3128", "https": "http://proxy.example:3128"}. Put proxy credentials in the proxy URL when required, install requests[socks] for SOCKS, and set explicit timeouts. Requests does not rotate IP addresses itself: your code must select endpoints, or you must use a provider gateway that documents rotation or sticky sessions.

How do I use a proxy with Python Requests?

A proxy mapping can be supplied to one request or stored on a Session. The mapping values are proxy URLs and must include a scheme. An HTTP proxy URL can be used for both HTTP and HTTPS destinations; HTTPS traffic is tunneled through it with CONNECT.

Per-request configuration

import requests

proxy_url = "http://proxy.example:3128"
proxies = {
    "http": proxy_url,
    "https": proxy_url,
}

response = requests.get(
    "https://example.com",
    proxies=proxies,
    timeout=(5, 20),
)
response.raise_for_status()
print(response.status_code)

Passing proxies on the individual call is the most explicit choice. The first timeout value limits connection establishment; the second limits waiting for response data. Requests has no default timeout, so production code should always set one.

Session-wide defaults

import requests

session = requests.Session()
session.proxies.update({
    "http": "http://proxy.example:3128",
    "https": "http://proxy.example:3128",
})

response = session.get("https://example.com", timeout=(5, 20))

A session is useful when many calls share a policy, but environment settings can affect it. Requests recognizes http_proxy, https_proxy, no_proxy, and all_proxy, plus uppercase variants. Those settings may override values held in session.proxies. If a particular request must use a known proxy, pass proxies directly on that call.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Prepared requests and environment settings

When you prepare a Request directly, environment proxy settings are not automatically incorporated. If your deployment relies on environment variables, prepare and send through a session while merging environment settings as described in the Requests advanced usage documentation. Alternatively, make the proxy explicit in the request call.

#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

How do I authenticate to a proxy in Requests?

For HTTP Basic proxy authentication, put the operator-supplied username and password in the proxy URL:

import requests

proxies = {
    "http": "http://USERNAME:PASSWORD@proxy.example:3128",
    "https": "http://USERNAME:PASSWORD@proxy.example:3128",
}

response = requests.get(
    "https://example.com",
    proxies=proxies,
    timeout=(5, 20),
)

Proxy credentials authenticate to the proxy, not to the destination website. Do not confuse them with Requests’ auth= argument, which is for origin (destination) authentication. Requests documents that credentials in the proxy URL take precedence over a manually supplied Proxy-Authorization header.

Keep credentials out of source control

  • Load credentials from a secret manager or controlled runtime configuration.
  • Never commit a complete proxy URL containing a password.
  • Be cautious with logs: exception messages, debug output, and copied URLs can expose credentials.
  • URL-encode reserved characters in usernames or passwords before constructing the proxy URL.

The Requests documentation warns against putting proxy credentials in environment variables or version-controlled files. A secret manager or injected process configuration with restricted access is safer than a literal in code.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Using SOCKS proxies: socks5 versus socks5h

Install the optional dependency first:

python -m pip install 'requests[socks]'

Then select a SOCKS URL in the mapping:

import requests

proxies = {
    "http": "socks5h://USERNAME:PASSWORD@proxy.example:1080",
    "https": "socks5h://USERNAME:PASSWORD@proxy.example:1080",
}

r = requests.get("https://example.com", proxies=proxies, timeout=(5, 20))
r.raise_for_status()
  • socks5 resolves the destination hostname on the client.
  • socks5h asks the proxy to resolve the hostname.

Use socks5h when DNS resolution should remain with the proxy, such as when the destination is only resolvable from the proxy’s network. The optional SOCKS dependency must be installed in the same Python environment that runs your program.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

HTTPS proxies, certificates, and verification

Requests verifies HTTPS certificates by default. As the Requests documentation states: “Requests verifies SSL certificates for HTTPS requests, just like a web browser.” A proxy can add another certificate requirement: if your HTTPS proxy intercepts TLS, the client may need to trust the proxy operator’s root CA.

Trust a required CA bundle

Install the organization’s CA bundle through your normal certificate-management process, then point Requests to it with REQUESTS_CA_BUNDLE (or CURL_CA_BUNDLE) or use the request’s verify setting with a bundle path.

import requests

r = requests.get(
    "https://example.com",
    proxies={
        "http": "http://proxy.example:3128",
        "https": "http://proxy.example:3128",
    },
    verify="/etc/ssl/company-proxy-ca.pem",
    timeout=(5, 20),
)

Do not casually set verify=False. It accepts untrusted or mismatched certificates and exposes the connection to man-in-the-middle attacks; reserve it for controlled testing with a clear risk assessment.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How do I rotate proxies in Python Requests?

Requests accepts proxy settings but has no built-in IP-rotation facility. There are two practical designs.

Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

Application-managed endpoint selection

Maintain a list of distinct endpoints and choose one before each request. Random selection is simple but can pick the same endpoint repeatedly. Round-robin selection is deterministic, but it does not prove that the next endpoint is healthy.

import itertools
import requests

proxy_urls = [
    "http://user:pass@proxy-a.example:3128",
    "http://user:pass@proxy-b.example:3128",
    "http://user:pass@proxy-c.example:3128",
]

if not proxy_urls:
    raise ValueError("At least one proxy endpoint is required")

cycle = itertools.cycle(proxy_urls)

for url in ("https://example.com/one", "https://example.com/two"):
    proxy_url = next(cycle)
    proxies = {"http": proxy_url, "https": proxy_url}
    try:
        response = requests.get(url, proxies=proxies, timeout=(5, 20))
        response.raise_for_status()
    except requests.exceptions.RequestException as exc:
        # Record the endpoint and apply your retry or quarantine policy.
        print(f"Proxy request failed via {proxy_url}: {exc}")

Keep endpoint selection separate from request code. Define what happens after connection failures, authentication errors, timeouts, and destination responses that indicate throttling. A failed endpoint should not necessarily be retried indefinitely; bound retries and record which endpoint was used.

Provider-managed gateway

Some proxy products expose one gateway URL while selecting or changing the exit IP upstream. The exact behavior depends on the provider product: verify rotation cadence, sticky-session controls, geography, authentication, and current terms. An integration guide from Oxylabs describes products with per-request rotation and sticky sessions, but it is an example of provider behavior rather than an independent performance test or endorsement.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Consideration Endpoint list in your application Provider-managed gateway
Rotation control Your code chooses an endpoint per request or policy. The provider changes the exit IP according to its configuration.
Repeated IP behavior Random may repeat; round-robin follows a predictable sequence. Depends on documented rotation and sticky-session settings.
Operational work Maintain inventory, credentials, health handling, and retries. Configure one gateway and understand account/session settings.
Geographic choice Limited to locations represented by your list. Depends on the product and supported targeting controls.

Changing an IP does not guarantee reliability, access, or permission to use a destination. Follow destination terms, applicable access rules, and published rate limits. Neither Requests nor the cited provider material establishes that rotation defeats blocks.

Why is Requests ignoring my proxy settings?

Environment variables override a session

Inspect http_proxy, https_proxy, all_proxy, no_proxy, and their uppercase forms in the process environment. A no_proxy entry can intentionally bypass the proxy for a host. Use a per-request proxies mapping when the route must be explicit.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

The mapping key does not match the destination

For an https:// URL, provide an https key. Ensure every proxy value includes a scheme such as http:// or socks5h://; a bare host:port is not a complete proxy URL.

Prepared requests skipped environment configuration

Prepare through a session and merge environment settings when you depend on them, or provide the proxy explicitly before sending.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Authentication or URL encoding is wrong

A 407 response generally means the proxy demanded authentication. Check the operator-issued credentials, port, scheme, and URL-encode special characters. Remember that auth= targets the destination, not the proxy.

TLS errors occur only through the proxy

Install and reference the proxy’s required root CA bundle. Do not use verify=False as a permanent fix.

Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

Timeouts and retries obscure the cause

Set a connect/read timeout tuple, catch requests.exceptions.RequestException, and log the endpoint, elapsed time, and failure category without logging secrets. A timeout does not prove that the remote server never received the request, so design non-idempotent retries carefully.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Operational checklist

  • Use a complete scheme in every proxy URL.
  • Pass proxies per request when deterministic routing matters.
  • Audit environment variables and no_proxy.
  • Install requests[socks] for SOCKS and choose DNS behavior deliberately.
  • Keep proxy credentials in controlled secret storage.
  • Keep certificate verification enabled and configure a trusted CA when required.
  • Set explicit connect and read timeouts.
  • Bound retries and record endpoint health.
  • Confirm provider rotation and sticky-session semantics before depending on them.

Or skip the browser setup

If your actual task is obtaining clean website screenshots rather than routing arbitrary Requests traffic, ScreenshotNeo provides a direct API and an MCP server for AI agents. One GET request returns PNG, JPEG, WebP, or PDF; cookie and consent banners, newsletter popups, and chat widgets are removed before capture. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed, and response headers identify the page verdict and billing status.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo API documentation for all options. Its MCP tools—take_screenshot, get_page_info, and capture_pdf—work with Claude, Cursor, and other MCP clients. The Free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots. Create a free ScreenshotNeo account.

FAQ

Can I use one proxy URL for both HTTP and HTTPS?

Yes. Map both destination schemes to the proxy URL, commonly an http:// proxy URL for each key.

Does Requests rotate proxies automatically?

No. Select endpoints in your application or use a provider gateway whose documented product behavior includes rotation.

Should I choose socks5 or socks5h?

Choose socks5 for client-side DNS resolution and socks5h for proxy-side DNS resolution.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.