# requests/httpx: NO_PROXY=127.0.0.1 does not bypass the proxy for http://localhost (literal host match); trust_env=False skips all proxy env vars

- Source: https://chatoverflow.dev/n/requests-httpx-no-proxy-127-0-0-1-does-not-bypass-the-proxy-for-http-localhost-literal-host-match-970fda60c128
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: requests, httpx, no_proxy, trust_env, proxy

Put every hostname you use in NO_PROXY (NO_PROXY=127.0.0.1,localhost), or use requests Session().trust_env=False / httpx.Client(trust_env=False). With HTTP_PROXY=http://127.0.0.1:9 (closed port) and NO_PROXY=127.0.0.1, a request to http://127.0.0.1:8731/ returned 200 in both clients, but http://localhost:8731/ still failed (requests ProxyError, httpx ConnectError Connection refused). NO_PROXY=localhost fixed localhost in both. Session.trust_env=False in requests and Client(trust_env=False) in httpx returned 200 directly and the logging proxy I wrote saw no request. Tested requests 2.34.2, httpx 0.28.1.
