More unique IPs than any network on the planet, in the world's largest residential pool. That's Shifter.More unique IPs than any network, in the world's largest pool. That's Shifter.

See the numbers

Python Proxy URLs Tested: SOCKS5 DNS, Password Characters and NO_PROXY

We tested how requests, httpx and aiohttp handle SOCKS5 DNS, special characters in proxy passwords and NO_PROXY. Three gaps can leak your IP or DNS.

Customer Success · Updated November 30, 2026 · 7 min read
raw passwordhttp://user:p#ss@host:8080URL ends hererequestsInvalidURLhttpxInvalidURLaiohttpInvalidURLpercent-encodedhttp://user:p%23ss@host:8080ok
The amber # in a raw password breaks the URL in requests, httpx and aiohttp alike.
Knowledge
On this page
  1. SOCKS5: who resolves the hostname
  2. Special characters in passwords
  3. Environment variables
  4. A setup that works everywhere
  5. Debugging a proxy URL
  6. How we tested
  7. The bottom line
  8. Sources and references

Most proxy problems in Python are not proxy problems. They come from the proxy URL: a password character that breaks parsing, a scheme that resolves DNS in the wrong place, an environment variable one library reads and another ignores. Our guide to using residential proxies with Python covers the basics. This post tests the edge cases. We ran 223 cases through requests, httpx and aiohttp against local test proxies that log exactly what each client sends.

Three findings matter most: socks5:// in requests resolves DNS on your machine, aiohttp ignores proxy environment variables by default, and *.example.com in NO_PROXY matches nothing.

SOCKS5: who resolves the hostname

A SOCKS5 client can send the proxy either a hostname or an IP address it has already looked up. If it looks up the address itself, the DNS query goes to your own resolver, outside the proxy, and the answer is chosen for your location, not the proxy’s.

Clientsocks5:// sendssocks5h:// sends
requestsIP address, resolved locallyHostname
httpxHostnameHostname
aiohttp with aiohttp-socksHostnameError: invalid scheme

With requests, socks5:// is a DNS leak: every lookup leaves from your own network, and sites behind a CDN may hand you an address near you rather than near the proxy. Use socks5h://. httpx always sent the hostname. aiohttp-socks sent the hostname with socks5:// and refused socks5h:// with ValueError: Invalid scheme component. Pass rdns=True to make remote resolution explicit.

Special characters in passwords

Proxy credentials go inside the URL, so characters that have a meaning in URLs can break it. We tested nine passwords, raw and percent-encoded, over HTTP and SOCKS5 proxies:

Password containsrequestshttpxaiohttpPercent-encoded
@WorksWorksWorksWorks
:WorksWorksWorksWorks
#URL errorURL errorURL errorWorks
/URL errorURL errorURL errorWorks
?URL errorURL errorURL errorWorks
% aloneWorksWorksWorksWorks
SpaceWorksWorksWorksWorks
%40 literallyWrong passwordWrong passwordWrong passwordWorks

The URL errors are at least loud: requests reports InvalidURL: Failed to parse, httpx Invalid port, aiohttp InvalidURL. The %40 case is silent. If your real password contains the text %40, every client decodes it to @ and sends the wrong password, and the proxy answers with a 407 authentication error that looks like a bad account.

The reason is URL syntax. Under RFC 3986, the credentials sit in the “userinfo” part, before the last @. A # starts the fragment, a ? starts the query and a / starts the path, so the parser ends the address at that character and reads what is left, here the start of your password, as the host and port. That is why the errors talk about an invalid port rather than a bad password. An @ or : survives because all three clients split credentials at the last @ and the first :, but that is a parser convenience, not something to rely on. A % followed by two hex digits is a percent-escape by definition, which is why %40 becomes @.

Percent-encoding fixed every ASCII case in every client:

from urllib.parse import quote

user = quote(os.environ["PROXY_USER"], safe="")
password = quote(os.environ["PROXY_PASS"], safe="")
proxy = f"http://{user}:{password}@PROXY_HOST:PORT"

Non-ASCII passwords are less predictable. Over an HTTP proxy, requests and aiohttp sent a password containing ä encoded as Latin-1 and httpx as UTF-8, so the same password reaches the proxy as different bytes depending on the library. Over SOCKS5, aiohttp-socks failed with a UnicodeEncodeError. Keep proxy passwords to ASCII letters, digits and simple symbols.

Environment variables

HTTP_PROXY, HTTPS_PROXY, ALL_PROXY and NO_PROXY let you set a proxy without touching code. The three clients do not read them the same way:

Settingrequestshttpxaiohttp
HTTP_PROXY and HTTPS_PROXYUsedUsedIgnored unless trust_env=True
Lowercase http_proxy and https_proxyUsedUsedSame as above
ALL_PROXY=socks5h://...UsedUsedIgnored, even with trust_env=True
Proxy passed in code, NO_PROXY matchesProxy usedProxy usedProxy used

The aiohttp default is the risky one. A script that works through the proxy with requests can be rewritten with aiohttp, and the same environment then sends every request directly from your own IP, with no error. Pass trust_env=True, or better, pass the proxy explicitly.

NO_PROXY lists hosts that should skip the proxy. For a request to site.example.test, with aiohttp set to trust_env=True:

NO_PROXY valueSkips the proxy?
example.testYes, in all three
.example.testYes, in all three
site.example.testYes, in all three
EXAMPLE.TESTYes, in all three
*Yes, in all three
*.example.testNo, in all three
exampleNo, in all three

The wildcard row is the trap. *.example.test looks like the obvious way to exclude a domain, but no client treats it as a pattern, so internal or excluded traffic keeps going through the proxy and is billed as proxy bandwidth.

A setup that works everywhere

  1. Build the URL in code from environment variables, percent-encoding the username and password.
  2. Use socks5h:// with requests. With aiohttp-socks, use socks5:// and rdns=True.
  3. Pass the proxy explicitly rather than relying on environment variables, so a library change cannot silently remove it.
  4. Write NO_PROXY entries as domains, example.com or .example.com, never *.example.com.
  5. Check your exit IP once at startup. The async proxy checker we built earlier shows a simple way.

For the choice between the two protocols, see HTTP vs SOCKS5 proxies. Shifter’s residential proxies support both HTTP and SOCKS5.

Debugging a proxy URL

When a proxy works in curl but not in Python, or in one library but not another, check these three things, in this order. First, print the parsed URL without the password: urllib.parse.urlsplit(proxy) shows the host and port the library will use, and a wrong port or a host that looks like part of your password points to an unencoded character. Second, check which proxy, if any, the library picked: in requests, requests.utils.get_environ_proxies(url) returns what it will take from the environment, and in aiohttp, remember that nothing is taken from the environment unless you asked for it. Third, compare the exit IP and the DNS location with what you expect. If the IP is the proxy’s but the DNS resolver is your own, you are on socks5:// with requests.

How we tested

On 30 November 2026 we ran local test proxies on 127.0.0.1, one SOCKS5 and two HTTP, that answered every request themselves and logged the target, the address type and the credentials received. No request left the machine through them. We tested Python 3.11.10 with requests 2.34.2 (urllib3 2.8.0, PySocks 1.7.1), httpx 0.29.0 (socksio 1.0.0) and aiohttp 3.14.5 (aiohttp-socks 0.12.0): two SOCKS schemes, nine passwords raw and percent-encoded over HTTP and SOCKS5, and eleven environment setups for HTTP and HTTPS targets. Each case ran in a fresh process with all other proxy variables removed.

The bottom line

Percent-encode proxy credentials, use socks5h:// with requests, and never trust NO_PROXY wildcards. Above all, do not assume a library reads your proxy environment variables: aiohttp does not, by default, and a script that silently goes direct is the hardest proxy mistake to notice.

Sources and references

Frequently asked questions

What is the difference between socks5 and socks5h in Python requests?

With socks5://, requests resolves the hostname on your own machine and sends the proxy an IP address, so your DNS lookups do not go through the proxy. With socks5h://, it sends the hostname and the proxy resolves it. In our test, httpx sent the hostname with either scheme, and aiohttp-socks sent it with socks5:// and rejected socks5h://.

How do I use a proxy password with special characters in Python?

Percent-encode the username and password before putting them in the proxy URL, for example with urllib.parse.quote(password, safe=""). In our test, raw #, / and ? characters broke the URL in all three clients, and a literal %40 was silently decoded to @. Encoding fixed every ASCII case.

Does aiohttp use HTTP_PROXY and HTTPS_PROXY environment variables?

Not by default. aiohttp ignores proxy environment variables unless you create the session with trust_env=True. requests and httpx read them by default. Even with trust_env=True, aiohttp ignored ALL_PROXY in our test.

Does NO_PROXY support wildcards like *.example.com?

Not in requests, httpx or aiohttp. In our test, NO_PROXY=*.example.test did not match site.example.test in any of the three clients, so the request still went through the proxy. Use example.test or .example.test instead, which matched subdomains in all three.

Ready to get started?

Try Shifter's residential proxies, 205M+ IPs, 195+ countries, from $0.10/GB.

Get Started