Fixing Missing dependencies for SOCKS support
One pip command fixes it. If you never asked for SOCKS, an environment variable did, and installing the package is the wrong fix.
In short
Run pip install "requests[socks]" in the environment your script uses. If your code has no SOCKS proxy in it, look for ALL_PROXY in your environment instead. Then write the proxy URL with socks5h://, so the proxy resolves hostnames.
requests speaks HTTP proxies out of the box. SOCKS is a different protocol, and requests hands it to a separate package, PySocks, which it does not install by default. The moment it meets a proxy URL starting with socks5://, socks5h:// or socks4:// without that package, it stops:
requests.exceptions.InvalidSchema: Missing dependencies for SOCKS support.Nothing was sent. The proxy, its address and your login have not been tested yet, so this error says nothing about whether they are right. Install the missing part:
python -m pip install "requests[socks]"Using python -m pip with the same python that runs your script matters. The usual reason the error survives the install is that pip put the package into another Python: the system one instead of your virtual environment, or the other way round.
Many people who search for this error have no proxy in their code at all. requests also takes proxies from the environment, and ALL_PROXY is a common one for VPN clients and proxy tools to set. We ran a plain requests.get(url) with no proxy argument:
Check with env | grep -i proxy. If the variable is a leftover, unset it. If you don’t want your script to follow the environment, use a Session with trust_env = False. Installing PySocks would make the error go away too, but then your script quietly sends everything through that proxy, which may not be what you want.
Both schemes work once PySocks is installed. The difference is who turns the website’s name into an IP address. With socks5:// your machine does the DNS lookup and hands the proxy an address. With socks5h:// the name goes to the proxy and is resolved there. We asked for a hostname that doesn’t exist, to see who answers:
| Scheme | Error for an unknown hostname | Who looked it up |
|---|---|---|
socks5:// | [Errno -2] Name or service not known | Your machine |
socks5h:// | 0x01: General SOCKS server failure | The proxy |
Use socks5h with a proxy
With socks5://, every hostname you visit is looked up from your own connection before the proxy is involved. That shows your resolver which sites you request, and a site that answers differently by region may hand you a server near you instead of near the exit. socks5h:// keeps the lookup on the proxy’s side.
The errors that come next
With PySocks installed, the proxy is finally contacted. These are the messages it produced when we broke the URL on purpose.
| Message | What we broke | Fix |
|---|---|---|
| SOCKS5 authentication failed | Wrong password, a targeting value the gateway can’t read, or a session on the rotating port | Copy the login again; check the targeting values and the port |
| All offered SOCKS5 authentication methods were rejected | No username and password in the URL | Add USER:PASS@ |
| 0x01: General SOCKS server failure | Filters no exit matches, or an unknown hostname | Remove the narrowest filter; check the URL |
| Connection closed unexpectedly | socks4:// on a SOCKS5 proxy | Use socks5h:// |
| Unable to determine SOCKS version from socks://… | The scheme socks:// | Write socks5h:// |
| [Errno 61] Connection refused | A port where nothing listens | Check the port |
| ConnectTimeoutError | A SOCKS URL pointing at an HTTP-only proxy | Use that proxy’s SOCKS port, or http:// |
SOCKS5 has no status codes
Over HTTP, a proxy can say 407 for a bad password and 403 for a username it can’t read. SOCKS5 only knows “authentication failed”. On our gateway a wrong password and a value it can’t read, such as -country-usa, gave the identical message. If you’re stuck, try the same login over http:// once to get the more specific answer; here is what each status means.
Don’t name your file socks.py
We did, while testing this article. PySocks is imported as socks, so Python loaded our own file instead and the script died with partially initialized module 'requests' has no attribute 'get'. Rename the file and delete the __pycache__ folder next to it.
httpx
httpx uses a different package and says so: Using SOCKS proxy, but the 'socksio' package is not installed. Install httpx[socks]. It accepts socks5:// and socks5h://; socks4:// fails with “Unknown scheme for proxy URL”. A wrong password reads ProxyError: Invalid username/password.
A setup that works
Our gateway takes SOCKS5 on port 11000 (12000 for sticky sessions) and HTTP on 9000. Both scripts ran as shown.
import os
import requests # pip install "requests[socks]"
USER = os.environ["PROXY_USER"]
PASS = os.environ["PROXY_PASS"]
# socks5h: the proxy resolves the hostname. socks5: your machine does.
proxy = f"socks5h://{USER}:{PASS}@via.proxies.vision:11000"
r = requests.get("https://ipinfo.io/ip", proxies={"http": proxy, "https": proxy}, timeout=30)
print(r.status_code, r.text.strip())import os
import httpx # pip install "httpx[socks]"
USER = os.environ["PROXY_USER"]
PASS = os.environ["PROXY_PASS"]
with httpx.Client(proxy=f"socks5h://{USER}:{PASS}@via.proxies.vision:11000", timeout=30) as client:
r = client.get("https://ipinfo.io/ip")
print(r.status_code, r.text.strip())Do you need SOCKS at all?
For fetching web pages, an HTTP proxy does the same job with no extra package and clearer errors: replace the scheme with http:// and the port with 9000, and keep the login. SOCKS5 earns its place when the traffic isn’t HTTP.
What is the pip command to fix 'Missing dependencies for SOCKS support'?
I installed PySocks and still get the error. Why?
I don't use SOCKS. Why do I get this error?
What is the difference between socks5:// and socks5h://?
How do I fix the same error in httpx?
Keep reading
aiohttp Proxy Errors: ClientHttpProxyError 407, SOCKS5 and trust_env
aiohttp's ClientHttpProxyError explained, why its message leaks your proxy password, socks5:// without aiohttp-socks, and rotation.
6 min read · #python#errors
curl: (56) CONNECT tunnel failed, response 407 — and git's Proxy CONNECT aborted
What curl's 'CONNECT tunnel failed, response 407' means, every curl proxy exit code we hit, and why git fails through a proxy that works in curl.
6 min read · #errors#authentication
Playwright Proxy Errors: ERR_TUNNEL_CONNECTION_FAILED, NS_ERROR_PROXY_*
Every Playwright proxy error in Chromium and Firefox, what the proxy answered, the silent 30-second timeout on a wrong password, and SOCKS5 auth.
7 min read · #playwright#errors
Residential proxies, pay per GB
HTTP and SOCKS5. Country, city and sticky sessions in the username. No subscription.