Skip to content
Fixedmark
Docs

Python HTTPS proxy setup

Send Python requests through your static IPs with requests, httpx, or aiohttp. All three accept the https:// proxy URL on current versions. Check the version table if you see TLS errors.

Docs preview: Fixedmark is not live yet. Endpoints are issued at launch, and these pages describe planned launch behavior. Anything marked planned may change. Join early access to get yours first.

requests

Pass the proxy URL for both keys of the proxies dict. The https key decides the proxy for HTTPS destinations. Its value is the proxy's own URL, which is also https://.

# pip install requests  (needs urllib3 1.26+ for an https:// proxy URL)
import os
import requests

proxy = os.environ["FIXEDMARK_PROXY_URL"]

# Pass proxies per request. On a Session, HTTPS_PROXY in the
# environment overrides session.proxies.
proxies = {"http": proxy, "https": proxy}

res = requests.get("https://api.partner.example/v1/orders", proxies=proxies, timeout=15)
print(res.status_code, res.json())

Set proxies on each request, not only on a Session. When HTTPS_PROXY is also set in the environment, requests lets the environment override session.proxies.

httpx

httpx takes a single proxy argument on the client. Version 0.26 added it, and 0.28 removed the older proxies argument, so target 0.28 or later. Use mounts if different hosts need different proxies.

# pip install "httpx>=0.28"  (proxy=; 0.28 removed proxies=)
import os
import httpx

with httpx.Client(proxy=os.environ["FIXEDMARK_PROXY_URL"], timeout=15) as client:
    res = client.get("https://api.partner.example/v1/orders")
    print(res.status_code, res.json())

# Async: httpx.AsyncClient(proxy=...) takes the same argument.

aiohttp

aiohttp takes proxy per request. Credentials in the URL work. An https:// proxy needs Python 3.11 or later, because older asyncio cannot run TLS inside TLS.

# pip install aiohttp  (Python 3.11+ for an https:// proxy URL)
import asyncio
import os
import aiohttp

PROXY = os.environ["FIXEDMARK_PROXY_URL"]

async def main():
    timeout = aiohttp.ClientTimeout(total=15)
    async with aiohttp.ClientSession(timeout=timeout) as session:
        async with session.get("https://api.partner.example/v1/orders", proxy=PROXY) as res:
            print(res.status, await res.json())

asyncio.run(main())

Version requirements

Minimum versions for an https:// proxy URL
LibraryMinimumSymptom when too old
requestsurllib3 1.26TLS or connection reset errors to port 443
httpx0.28 recommendedTypeError on proxy (before 0.26) or proxies (0.28+)
aiohttpPython 3.11Cannot initialize a TLS-in-TLS connection
Tested with requests 2.33 and urllib3 2.8, httpx 0.28, and aiohttp 3.14 on Python 3.11 and 3.14, against a local TLS-wrapped CONNECT proxy. aiohttp on Python 3.10 failed with the TLS-in-TLS error above.

Environment variables

requests and httpx read HTTPS_PROXY, HTTP_PROXY, and NO_PROXY unless you turn that off. aiohttp reads them only with ClientSession(trust_env=True). A global variable also proxies calls to your own services and counts them against your plan, so prefer passing the proxy in code.

SOCKS5

Install requests[socks] or httpx[socks] to use the SOCKS5 URL. Keep socks5h:// so DNS resolves on the proxy. For aiohttp, the aiohttp-socks package adds a SOCKS connector. Database drivers such as psycopg have no SOCKS5 option. See databases.

# pip install "requests[socks]"
import os
import requests

# Keep the socks5h:// scheme so the proxy resolves DNS.
socks = os.environ["FIXEDMARK_SOCKS_URL"]
res = requests.get("https://api.partner.example/v1/orders", proxies={"http": socks, "https": socks}, timeout=15)
print(res.status_code)

Platform guides

Frequently asked questions

Does Python requests support an HTTPS proxy?

Yes, with urllib3 1.26 or later. Pass the https:// proxy URL in the proxies dict for both the http and https keys.

Why does aiohttp fail with a TLS-in-TLS error?

asyncio cannot start TLS inside an existing TLS connection before Python 3.11. Upgrade to Python 3.11 or later, or use httpx's AsyncClient.

Do I need to change code if I set HTTPS_PROXY?

requests and httpx read HTTPS_PROXY and NO_PROXY by default. aiohttp reads them only with ClientSession(trust_env=True). Passing the proxy in code is clearer and limits it to the calls that need it.

Make it fixed.

Fixedmark is in early access. Join the list to get dedicated static IPs when your region opens.