Missing Dependencies for SOCKS Support: How to Fix It
Requests can work with SOCKS proxies, but only after an extra package is installed. Without it, the very first request through socks5:// ends with an InvalidSchema exception.
Updated · Prokso editorial team
- Missing dependencies for SOCKS support means the PySocks package is not installed for requests
- Install it with the same Python that runs the script: python -m pip install 'requests[socks]'
- For residential proxies use socks5h, so the proxy, not your computer, turns the site name into an IP
What the error means
The full text is requests.exceptions.InvalidSchema: Missing dependencies for SOCKS support. In the requests source code, this exception is raised when the SOCKS module from urllib3 could not be imported, and that module in turn needs the PySocks package. Requests itself is installed without it, because, according to the documentation, SOCKS support is optional.
The error does not appear on import, but on the first request through a proxy with the socks5://, socks5h:// or socks4:// scheme. That is why code with an HTTP proxy works and then suddenly fails after you switch the line to SOCKS. The request reaches neither the proxy nor the site, so no traffic is used.
After installing the dependencies, the choice of scheme matters. According to the requests documentation, with the socks5 scheme your computer turns the site name into an IP, and with socks5h the proxy does it. Residential proxies usually need socks5h: then the DNS lookup comes from the same country as the IP.
Causes
- PySocks is not installed. Neither requests[socks] nor PySocks was installed, so urllib3 cannot load its SOCKS module.
- The package is in a different environment. pip installed PySocks for a different Python or a different virtual environment than the one that runs the script.
- The zsh shell ate the square brackets. The command pip install requests[socks] without quotes fails in zsh with no matches found, and nothing gets installed.
- A build without optional packages. A Docker image, a server or an app build installs only requests from requirements.txt, which does not list PySocks.
How to fix it
- Install the dependencies with the same interpreter that runs the script:
python -m pip install 'requests[socks]'. The quotes are needed for zsh. - Check that the package is there:
python -c "import socks; print(socks.__file__)". If the import fails, you installed it into a different environment. - Add
requests[socks]to requirements.txt or pyproject.toml so the dependency is installed on the server and in Docker too. - Set the proxy with the socks5h scheme for both keys:
proxies={'http': 'socks5h://USERNAME:PASSWORD@gw.prokso.com:824', 'https': 'socks5h://USERNAME:PASSWORD@gw.prokso.com:824'}. For a sticky IP, use a port from the 10000-20000 range instead of 824. - If after installation you get a
ConnectionErrorwith the text SOCKS5 authentication failed, the proxy did not accept the username or password: copy the line from the dashboard again. A full code example is in the Python requests guide.
How to check that it works
Run requests.get('https://prokso.com/ip', proxies=proxies, timeout=30).json(). If the response shows the IP, country and ASN of the proxy, SOCKS works. Then open My IP without the proxy and compare: the addresses should differ.
Two-minute diagnosis
First paste the line into the proxy checker. If the proxy works there, the cause is in your app or its settings. If not, test the line from a terminal:
curl -v -x "http://USERNAME:PASSWORD@gw.prokso.com:823" https://api.ipify.org
- A
< HTTP/1.1 407line right afterCONNECTmeans the proxy answered. The name after the code, for exampleNO_USER, points to the cause. - The proxy answered
CONNECTwith 200 and then another code arrived - the proxy works, and that answer came from the website. - No answer at all, only a timeout - the connection never reached the proxy: check the host, port and network.
Setup guides where this error comes up
FAQ
How is socks5 different from socks5h?
Only in who turns the site name into an IP. With socks5 your computer does it, and your DNS server sees where you go; with socks5h the proxy does it. More about the protocol is in the glossary: <a href="/en/glossary/socks5">SOCKS5</a>.
Why do I get ConnectionError rather than ProxyError after installing?
For SOCKS, urllib3 raises connection errors as NewConnectionError, and requests turns them into ConnectionError. Look for the cause in the text after Failed to establish a new connection. SOCKS server refusals are covered on the <a href="/en/errors/socks5-general-failure">SOCKS5 general failure</a> page.
What if the connection to port 824 is refused?
Check the host gw.prokso.com, the port and your network: some networks block non-standard ports. Details are on the <a href="/en/errors/socks5-connection-refused">SOCKS5 connection refused</a> page.
Do httpx or aiohttp need PySocks?
No, they have their own dependencies: httpx needs httpx[socks], and aiohttp works with SOCKS only through the separate aiohttp-socks package.
Other proxy errors
Residential $1.59, mobile $2.50, datacenter $0.65 per GB
Sign up in a minute, get access right after payment.