Skip to content

Instantly share code, notes, and snippets.

@quantumproxies
Created July 28, 2026 09:47
Show Gist options
  • Select an option

  • Save quantumproxies/13379e983a271ed1660c4e3aa560b92d to your computer and use it in GitHub Desktop.

Select an option

Save quantumproxies/13379e983a271ed1660c4e3aa560b92d to your computer and use it in GitHub Desktop.
HTTP_PROXY / HTTPS_PROXY in Python: trust_env, NO_PROXY and the pitfalls nobody documents — https://quantumproxies.io/rotating-proxies
# HTTP_PROXY / HTTPS_PROXY in Python: the pitfalls nobody documents.
#
# 1) requests reads env vars ONLY if trust_env is True (default) — and
# HTTPS_PROXY must still be an http:// URL (it's the scheme of the
# *target*, not of the proxy).
# 2) NO_PROXY beats both — a stray NO_PROXY=* silently disables everything.
# 3) urllib/requests lowercase vs uppercase: both are read, lowercase wins.
#
# Proxy used in the example: QuantumProxies rotating residential
# https://quantumproxies.io/rotating-proxies (creds: app.quantumproxies.io/register)
import os
import requests
os.environ["HTTP_PROXY"] = "http://USER-country-us:PASS@residentialboson.quantumproxies.io:9000"
os.environ["HTTPS_PROXY"] = os.environ["HTTP_PROXY"] # yes, http:// for both
os.environ.pop("NO_PROXY", None) # pitfall #2
print(requests.get("https://ipinfo.io/json", timeout=30).json())
# Opting OUT for one call while env vars are set:
s = requests.Session()
s.trust_env = False # ignore proxy env entirely
print(s.get("https://ipinfo.io/json", timeout=30).json())
# Opting IN explicitly (wins over env, survives trust_env=False):
proxies = {"http": os.environ["HTTP_PROXY"], "https": os.environ["HTTP_PROXY"]}
print(requests.get("https://ipinfo.io/json", proxies=proxies, timeout=30).json())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment