title: Python's requests "Missing dependencies for SOCKS support" when using SOCKS5 from Terminal
body: <p>I'm trying to interact with an API from my Python 2.7 shell using a package that relies on Python's requests. Thing is the remote address is blocked by my network (university library). </p>
  
  <p>So to speak to the API I do the following:</p>
  
  <pre><code>~$ ssh -D 8080 name@myserver.com
  </code></pre>
  
  <p>And then, in new terminal, in local computer:</p>
  
  <pre><code>~$ export http_proxy=socks5://127.0.0.1:8080 https_proxy=socks5://127.0.0.1:8080
  </code></pre>
  
  <p>Then I run the program in Python console but fails:</p>
  
  <pre><code>~$ python
  &gt;&gt;&gt; import myscript
  &gt;&gt;&gt; id = '1213'
  &gt;&gt;&gt; token = 'jd87jd9'
  &gt;&gt;&gt; connect(id,token)
  
  File "/home/username/.virtualenvs/venv/local/lib/python2.7/site-packages/requests/sessions.py", line 518, in post
      return self.request('POST', url, data=data, json=json, **kwargs)
    File "/home/username/.virtualenvs/venv/local/lib/python2.7/site-packages/requests/sessions.py", line 475, in request
      resp = self.send(prep, **send_kwargs)
    File "/home/username/.virtualenvs/venv/local/lib/python2.7/site-packages/requests/sessions.py", line 585, in send
      r = adapter.send(request, **kwargs)
    File "/home/username/.virtualenvs/venv/local/lib/python2.7/site-packages/requests/adapters.py", line 370, in send
      conn = self.get_connection(request.url, proxies)
    File "/home/username/.virtualenvs/venv/local/lib/python2.7/site-packages/requests/adapters.py", line 273, in get_connection
      proxy_manager = self.proxy_manager_for(proxy)
    File "/home/username/.virtualenvs/venv/local/lib/python2.7/site-packages/requests/adapters.py", line 169, in proxy_manager_for
      **proxy_kwargs
    File "/home/username/.virtualenvs/venv/local/lib/python2.7/site-packages/requests/adapters.py", line 43, in SOCKSProxyManager
      raise InvalidSchema("Missing dependencies for SOCKS support.")
  requests.exceptions.InvalidSchema: Missing dependencies for SOCKS support.
  </code></pre>
  
  <p>This excerpt is from the <a href="http://docs.python-requests.org/en/master/_modules/requests/adapters/" rel="noreferrer">adapters.py requests module</a>:</p>
  
  <pre><code>&gt; try:
  &gt;     from .packages.urllib3.contrib.socks import SOCKSProxyManager except ImportError:
  &gt;     def SOCKSProxyManager(*args, **kwargs):
  &gt;         raise InvalidSchema("Missing dependencies for SOCKS support.")
  </code></pre>
  
  <p>Now problem seems to be originated in urllib3's SOCKSProxyManager.</p>
  
  <p>So I read you can use SOCKSProxyManager with SOCKS5 if you have install <a href="https://pypi.python.org/pypi/PySocks" rel="noreferrer">PySocks</a> or you do a <em>pip install urllib3[socks]</em></p>
  
  <p>Alas, I tried both PySocks and urllib3 with Socks without any success.</p>
  
  <p>Any idea of another workaround?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I also tried <em>pip install requests[socks]</em> (that's requests 2.10.0 with Socks support) and I am getting this:</p>
  
  <pre><code>  File "/home/username/.virtualenvs/venv/local/lib/python2.7/site-packages/requests/adapters.py", line 467, in send
      raise ConnectionError(e, request=request)
  requests.exceptions.ConnectionError: SOCKSHTTPSConnectionPool(host='api-server.com', port=443): Max retries exceeded with url: /auth (Caused by NewConnectionError('&lt;requests.packages.urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x95c7ccc&gt;: Failed to establish a new connection: SOCKS5 proxy server sent invalid data',))
  </code></pre>