DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
HTTP

How to Use Proxies With Python HTTPX

Free tools Windows power users keep installed

One-click scans. No signup required.

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

For a single proxy, pass its URL as proxy= when creating an HTTPX client or making a top-level request. For different proxy routes, configure transports in mounts. A common surprise: when routing HTTPS destinations through a standard HTTP proxy, the proxy URL often still starts with http://. The destination uses HTTPS; the client tunnels through the HTTP proxy and establishes TLS with the destination.

Use one proxy for HTTPX requests

HTTPX supports a proxy parameter on both clients and top-level request functions. A client is usually the better choice for a series of requests: it can reuse connections, and using a context manager ensures the client is closed when the work is done.

Client for multiple requests

import httpx

proxy_url = "http://proxy-host:port"

with httpx.Client(proxy=proxy_url, timeout=20.0) as client:
    response = client.get("https://example.com/")
    response.raise_for_status()
    print(response.status_code)
    print(response.url)

Replace proxy-host:port with the endpoint supplied by your proxy operator. The example requests an HTTPS destination through a proxy whose URL uses HTTP, a common HTTPX configuration explained below. If you need one request only, you can pass the same setting directly to the top-level API:

import httpx

response = httpx.get(
    "https://example.com/",
    proxy="http://proxy-host:port",
    timeout=20.0,
)
response.raise_for_status()
print(response.status_code)

These examples use a synchronous client. The proxy setting changes the route used by the request; it does not change the requested URL or guarantee that a destination will accept the request.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
TP-Link ER605, Wired Gigabit VPN Router
  • 【Five Gigabit Ports】1 Gigabit WAN Port plus 2 Gigabit WAN/LAN Ports plus 2 Gigabit LAN Port. Up to 3 WAN ports optimize bandwidth usage through one device.
  • 【One USB WAN Port】Mobile broadband via 4G/3G modem is supported for WAN backup by connecting to the USB port. For complete list of compatible 4G/3G modems, please visit TP-Link website.
  • 【Abundant Security Features】Advanced firewall policies, DoS defense, IP/MAC/URL filtering, speed test and more security functions protect your network and data.
  • 【Highly Secure VPN】Supports up to 20× LAN-to-LAN IPsec, 16× OpenVPN, 16× L2TP, and 16× PPTP VPN connections.
  • Security - SPI Firewall, VPN Pass through, FTP/H.323/PPTP/SIP/IPsec ALG, DoS Defence, Ping of Death and Local Management. Standards and Protocols IEEE 802.3, 802.3u, 802.3ab, IEEE 802.3x, IEEE 802.1q

Authenticate to the proxy

If the proxy requires username and password authentication, HTTPX accepts credentials in the proxy URL’s user information:

proxy_url = "http://username:password@proxy-host:port"

with httpx.Client(proxy=proxy_url, timeout=20.0) as client:
    response = client.get("https://example.com/")
    response.raise_for_status()

Use the actual scheme and credentials specified by the proxy operator. Avoid committing credentials to source control or printing them in diagnostic logs. Characters reserved in a URL may need correct URL encoding; if authentication fails, confirm the exact endpoint format and credential requirements with the operator.

Route HTTP and HTTPS destinations through different proxies

Use mounts when routing should vary by scheme, domain, or port. Each mapping value is a transport; the transport carries the proxy setting for requests matching its mount pattern.

import httpx

proxy_mounts = {
    "http://": httpx.HTTPTransport(proxy="http://localhost:8030"),
    "https://": httpx.HTTPTransport(proxy="http://localhost:8031"),
}

with httpx.Client(mounts=proxy_mounts, timeout=20.0) as client:
    http_response = client.get("http://example.com/")
    https_response = client.get("https://example.com/")
    http_response.raise_for_status()
    https_response.raise_for_status()

The keys describe the destination URL scheme, not necessarily the scheme of the proxy endpoint. HTTPX matches mount patterns from more specific to less specific. Its patterns can target schemes, domains, and ports, so a domain-specific route can take precedence over a general scheme route. A matching mount set to None bypasses the proxy.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
GL.iNet GL-SFT1200 Opal Travel Router, AC1200 Dual-Band Wi-Fi
  • 【AC1200 Dual-band Wireless Router】Simultaneous dual-band with wireless speed up to 300 Mbps (2.4GHz) + 867 Mbps (5GHz). 2.4GHz band can handles some simple tasks like emails or web browsing while bandwidth intensive tasks such as gaming or 4K video streaming can be handled by the 5GHz band.*Speed tests are conducted on a local network. Real-world speeds may differ depending on your network configuration.*
  • 【Easy Setup】Please refer to the User Manual and the Unboxing & Setup video guide on Amazon for detailed setup instructions and methods for connecting to the Internet.
  • 【Pocket-friendly】Lightweight design(145g) which designed for your next trip or adventure. Alongside its portable, compact design makes it easy to take with you on the go.
  • 【Full Gigabit Ports】Gigabit Wireless Internet Router with 2 Gigabit LAN ports and 1 Gigabit WAN ports, ideal for lots of internet plan and allow you to connect your wired devices directly.
  • 【Keep your Internet Safe】IPv6 supported. OpenVPN & WireGuard pre-installed, compatible with 30+ VPN service providers. Cloudflare encryption supported to protect the privacy.

This is not the same configuration shape as Requests’ proxies={"http": ..., "https": ...} mapping. In HTTPX, provide transports through mounts; put the proxy URL on each HTTPTransport.

Bypass a proxy for a specific destination

A more specific mount can opt a host out of a broader proxy rule. For example, this client proxies general HTTPS traffic but bypasses the proxy for internal.example.com:

import httpx

mounts = {
    "https://internal.example.com": None,
    "https://": httpx.HTTPTransport(proxy="http://localhost:8031"),
}

with httpx.Client(mounts=mounts, timeout=20.0) as client:
    response = client.get("https://internal.example.com/status")
    response.raise_for_status()

Use the exact mount pattern syntax supported by your installed HTTPX version when adding domain or port-specific rules. A broad scheme pattern is convenient, while a narrower pattern reduces the chance that a route affects unrelated destinations.

Why an HTTPS destination often uses an HTTP proxy URL

Do not confuse the scheme of the destination with the scheme of the proxy. For a typical HTTP proxy routing an HTTPS URL, the client asks the proxy to establish a tunnel to the destination, then uses that tunnel for TLS. The proxy URL for a mount such as "https://" is therefore commonly written with an http:// scheme:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
ASUS RT-AX1800S Dual Band WiFi 6 Extendable Router, Subscription-Free Network Security, Parental Control, Built-in VPN, AiMesh Compatible, Gaming & Streaming, Smart Home
  • New-Gen WiFi Standard – WiFi 6(802.11ax) standard supporting MU-MIMO and OFDMA technology for better efficiency and throughput.Antenna : External antenna x 4. Processor : Dual-core (4 VPE). Power Supply : AC Input : 110V~240V(50~60Hz), DC Output : 12 V with max. 1.5A current.
  • Ultra-fast WiFi Speed – RT-AX1800S supports 1024-QAM for dramatically faster wireless connections
  • Increase Capacity and Efficiency – Supporting not only MU-MIMO but also OFDMA technique to efficiently allocate channels, communicate with multiple devices simultaneously
  • 5 Gigabit ports – One Gigabit WAN port and four Gigabit LAN ports, 10X faster than 100–Base T Ethernet.
  • Commercial-grade Security Anywhere – Protect your home network with AiProtection Classic, powered by Trend Micro. And when away from home, ASUS Instant Guard gives you a one-click secure VPN.
"https://": httpx.HTTPTransport(proxy="http://proxy-host:port")

That is not a contradiction: https:// identifies the destination requests being matched, while http:// identifies how the client connects to the proxy. HTTPX’s proxy guidance distinguishes forwarding, where the proxy makes the request, from tunnelling, where it creates a TCP connection that the client reuses for TLS.

A proxy URL beginning with https:// is a different setup. HTTPX’s troubleshooting documentation currently flags HTTPS-proxy support as a limitation. This is version-sensitive: if the proxy endpoint itself requires HTTPS, check the current HTTPX troubleshooting guidance for your installed version instead of assuming that changing the URL scheme will work.

Use environment variables or explicit settings

By default, HTTPX reads proxy configuration from the environment. The recognized variables include HTTP_PROXY, HTTPS_PROXY, and ALL_PROXY; NO_PROXY identifies hosts or URLs that should bypass a proxy. Environment configuration is useful when deployment settings should control routing without changing application code, but it can also explain why a request takes an unexpected route.

To ignore ambient proxy and certificate-related environment settings for a client or request, use trust_env=False:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Sale
GL.iNet GL-BE3600 Slate 7 Wi-Fi 7 Travel Router Touchscreen 2.5G
  • 【DUAL BAND WIFI 7 TRAVEL ROUTER】Products with US, UK, EU, AU Plug; Dual band network with wireless speed 688Mbps (2.4G)+2882Mbps (5G); Dual 2.5G Ethernet Ports (1x WAN and 1x LAN Port); USB 3.0 port.
  • 【NETWORK CONTROL WITH TOUCHSCREEN SIMPLICITY】Slate 7’s touchscreen interface lets you scan QR codes for quick Wi-Fi, monitor speed in real time, toggle VPN on/off, and switch providers directly on the display. Color-coded indicators provide instant network status updates for Ethernet, Tethering, Repeater, and Cellular modes, offering a seamless, user-friendly experience.
  • 【OpenWrt 23.05 FIRMWARE】The Slate 7 (GL-BE3600) is a high-performance Wi-Fi 7 travel router, built with OpenWrt 23.05 (Kernel 5.4.213) for maximum customization and advanced networking capabilities. With 512MB storage, total customization with open-source freedom and flexible installation of OpenWrt plugins.
  • 【VPN CLIENT & SERVER】OpenVPN and WireGuard are pre-installed, compatible with 30+ VPN service providers (active subscription required). Simply log in to your existing VPN account with our portable wifi device, and Slate 7 automatically encrypts all network traffic within the connected network. Max. VPN speed of 100 Mbps (OpenVPN); 540 Mbps (WireGuard). *Speed tests are conducted on a local network. Real-world speeds may differ depending on your network configuration.*
  • 【PERFECT PORTABLE WIFI ROUTER FOR TRAVEL】The Slate 7 is an ideal portable internet device perfect for international travel. With its mini size and travel-friendly features, the pocket Wi-Fi router is the perfect companion for travelers in need of a secure internet connectivity on the go in which includes hotels or cruise ships.
import httpx

with httpx.Client(trust_env=False, timeout=20.0) as client:
    response = client.get("https://example.com/")
    response.raise_for_status()

Or on a top-level call:

import httpx

response = httpx.get(
    "https://example.com/",
    trust_env=False,
    timeout=20.0,
)
response.raise_for_status()

Use this when you need a request to ignore proxy settings inherited from the process environment. It also ignores other environment settings HTTPX trusts, including certificate-related settings, so do not treat it as a proxy-only switch. If you want explicit routing while suppressing environment configuration, pass the proxy or mounts you intend to use and set trust_env=False.

Configure SOCKS proxies

SOCKS support is optional. Install HTTPX with its SOCKS extra rather than assuming a base HTTPX installation includes it:

pip install "httpx[socks]"

Then supply a SOCKS URL as the client proxy:

import httpx

proxy_url = "socks5://user:pass@proxy-host:port"

with httpx.Client(proxy=proxy_url, timeout=20.0) as client:
    response = client.get("https://example.com/")
    response.raise_for_status()

The optional SOCKS dependency is socksio. If HTTPX reports that SOCKS support is unavailable, install the extra in the same Python environment where the application runs, then restart that environment. Use the SOCKS scheme and authentication format specified by your endpoint provider; do not infer that an HTTP proxy endpoint can be used as a SOCKS endpoint.

Choose synchronous or asynchronous clients

HTTPX provides both Client and AsyncClient, with sync and async APIs and connection pooling. Use the synchronous form for ordinary blocking scripts. Use an asynchronous client when the surrounding application already uses asyncio and needs to make requests without blocking its event loop.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
TP-Link Dual-Band AX3000 Wi-Fi 6 Wireless Gigabit Internet Router for Home
  • Next-Gen Gigabit Wi-Fi 6 Speeds: 2402 Mbps on 5 GHz and 574 Mbps on 2.4 GHz bands ensure smoother streaming and faster downloads; support VPN server and VPN client¹
  • A More Responsive Experience: Enjoy smooth gaming, video streaming, and live feeds simultaneously. OFDMA makes your Wi-Fi stronger by allowing multiple clients to share one band at the same time, cutting latency and jitter.²
  • Expanded Wi-Fi Coverage: 4 high-gain external antennas and Beamforming technology combine to extend strong, reliable, Wi-Fi throughout your home.
  • Improved Battery Life: Target Wake Time helps your devices to communicate efficiently while consuming less power.
  • Improved Cooling Design: No heat ups, no throttles. A larger heat sink and redefined case design cools the WiFi 6 system and enables your network to stay at top speeds in more versatile environments.
import asyncio
import httpx

async def main():
    async with httpx.AsyncClient(
        proxy="http://proxy-host:port",
        timeout=20.0,
    ) as client:
        response = await client.get("https://example.com/")
        response.raise_for_status()
        print(response.status_code)

asyncio.run(main())

Keep a client alive for the set of work that should share its connection pool rather than creating a new client for every request. An AsyncClient can be shared between tasks; close it when its application-level lifetime ends. HTTPX also supports HTTP/1.1 and HTTP/2, but a particular proxy and destination determine which connections can actually be used.

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

Troubleshoot common proxy failures

Symptom Likely cause What to check
An HTTPS request fails with an unexpected proxy error The proxy URL was set to https:// because the destination is HTTPS. For a typical HTTP proxy, try the proxy endpoint’s http:// URL while keeping the destination URL as https://. If the endpoint itself requires HTTPS, consult the current HTTPX troubleshooting guidance; HTTPS-proxy support is a documented, version-sensitive concern.
HTTP requests work, but HTTPS routing does not The proxy may not support tunnelling, the HTTPS mount may not match, or the proxy URL scheme may be wrong. Check the https:// mount key, the HTTPTransport(proxy=...) endpoint, and whether the proxy supports tunnels to the destination port.
Requests use a proxy you did not configure in code HTTPX reads proxy environment variables by default. Inspect HTTP_PROXY, HTTPS_PROXY, ALL_PROXY, and NO_PROXY. Use trust_env=False if the request must ignore trusted environment settings.
One host unexpectedly bypasses the proxy A NO_PROXY entry or a more-specific mount may match that destination. Check environment configuration and mount patterns, including any entry set to None.
SOCKS configuration fails or SOCKS support is missing The optional dependency may not be installed in the active environment, or the endpoint may not be a SOCKS endpoint. Install httpx[socks] in the runtime environment and verify the endpoint’s scheme, address, port, and credentials.
Authentication is rejected Credentials or URL formatting may not match the proxy operator’s requirements. Confirm the endpoint and authentication format with the operator; check URL-escaped reserved characters and ensure the password is not being altered by configuration handling.
The request reaches the proxy but the destination rejects or times out The proxy may be unable to reach the destination, the destination may reject the request, or the configured timeout may be too short for the operation. Verify destination access and proxy policy independently, then choose a timeout appropriate to the request. A proxy setting cannot guarantee successful access.

HTTPX requires Python 3.9 or newer, according to its project documentation. When behavior or HTTPS-proxy support is uncertain, check the documentation for the HTTPX version actually installed rather than assuming examples and troubleshooting notes are invariant across releases.

Operational notes: security, performance, and cost

  • Credentials: Keep proxy passwords out of committed source code and logs. Prefer deployment-managed secrets and limit who can read them.
  • Privacy: A proxy changes the network route; it does not by itself guarantee anonymity, privacy, or secure handling by the proxy operator. HTTPS protects traffic between the client and destination when TLS is correctly established, but does not make an untrusted proxy a trusted party.
  • Performance: HTTPX clients provide connection pooling, which avoids repeatedly creating clients for related work. The actual latency and reliability depend on the proxy, network path, destination, and workload; no universal speed gain follows from using a proxy.
  • Cost and access: Proxy service prices, usage limits, allowed destinations, and reliability depend on the operator and plan. Check those terms directly. A proxy does not make access to a blocked service lawful or ensure the service will allow the request.

When the task is a webpage screenshot, not an HTTP response

HTTPX fetches HTTP responses; it does not render a page in a browser. If your goal is a screenshot or PDF of a rendered webpage, a screenshot API may be a better fit than assembling browser automation around an HTTP client. ScreenshotNeo is a website screenshot API and MCP server from Yorker Media; it returns PNG, JPEG, WebP, or PDF captures. It is not an HTTPX proxy and does not replace the proxy configurations above.

Or skip the browser setup

One Python request captures a target URL:

import requests

r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://example.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)

See the ScreenshotNeo documentation for API details. It accepts cookie and consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each of those steps can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status. Its MCP server offers take_screenshot, get_page_info, and capture_pdf tools for AI agents. The Free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000 shots. Sign up for 1,000 free screenshots a month with no card.

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

Frequently Asked Questions

Can I use HTTPX with an HTTP/2-enabled request through a proxy?

HTTPX supports HTTP/2, but whether it is usable for a particular request depends on the proxy and destination connection. Check the capabilities of both endpoints for your setup.

Does an HTTPX proxy setting make a request anonymous?

No. It changes the route for the request, but does not guarantee anonymity or determine how the proxy operator handles traffic.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

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

Read next

Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.