Created
July 28, 2026 09:47
-
-
Save quantumproxies/0f9c7865b7acea0fd43946f23cb9eb19 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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