Originally opened by @kgtl12 on 2025-04-24 09:42:41 in encode/httpx
Description:
I'm trying to make HTTP requests through a SOCKS5 proxy with username/password authentication.
Working (synchronous requests):
This works fine using the requests library:
import requests
proxies = {
"http": "socks5://<username>:<password>`@p`.webshare.io:80",
"https": "socks5://<username>:<password>`@p`.webshare.io:80"
}
response = requests.get(
url="https://httpbin.org/ip",
headers={"User-Agent": "MyAgent"},
proxies=proxies,
timeout=10
)
print(response.text)
Not working (async httpx):
With the async httpx client, I get a 407 Proxy Authentication Required error:
import httpx
proxy_url = "socks5://<username>:<password>`@p`.webshare.io:80"
async with httpx.AsyncClient(proxies=proxy_url, timeout=10) as client:
response = await client.get(
url="https://httpbin.org/ip",
headers={"User-Agent": "MyAgent"},
)
The error is:
httpx.ProxyError: [Errno 407] Proxy Authentication Required
Also fails with aiohttp:
Even when using aiohttp and passing proxy_auth, I still get authentication issues:
import aiohttp
auth = aiohttp.BasicAuth("<username>", "<password>")
async with aiohttp.ClientSession() as session:
async with session.get(
url="https://httpbin.org/ip",
proxy="http://p.webshare.io:80",
proxy_auth=auth
) as resp:
print(await resp.text())
Tested via cURL (also works):
curl --proxy "socks5://<username>:<password>`@p`.webshare.io:80/" https://httpbin.org/ip
This works and returns the proxy IP.
What I've Tried:
- Confirmed credentials are correct (works with cURL and
requests)
- Tried both
http:// and socks5:// proxy schemes in aiohttp and httpx
- Checked for whitespace or malformed proxy strings
- Looked into environment variables (
HTTP_PROXY, HTTPS_PROXY)
- Tried rotating IPs and ports on the provider side
- Tried
aiohttp_socks ProxyConnector.
Question:
Why does this SOCKS5 proxy with authentication work in requests and curl, but fail in both httpx and aiohttp with a 407 Proxy Authentication Required error?
Any guidance or insights on async-compatible SOCKS5 proxy usage with auth would be appreciated!
Description:
I'm trying to make HTTP requests through a SOCKS5 proxy with username/password authentication.
Working (synchronous
requests):This works fine using the
requestslibrary:Not working (async
httpx):With the async
httpxclient, I get a407 Proxy Authentication Requirederror:The error is:
Also fails with
aiohttp:Even when using
aiohttpand passingproxy_auth, I still get authentication issues:Tested via cURL (also works):
curl --proxy "socks5://<username>:<password>`@p`.webshare.io:80/" https://httpbin.org/ipThis works and returns the proxy IP.
What I've Tried:
requests)http://andsocks5://proxy schemes inaiohttpandhttpxHTTP_PROXY,HTTPS_PROXY)aiohttp_socksProxyConnector.Question:
Why does this SOCKS5 proxy with authentication work in
requestsandcurl, but fail in bothhttpxandaiohttpwith a407 Proxy Authentication Requirederror?Any guidance or insights on async-compatible SOCKS5 proxy usage with auth would be appreciated!