2.11.0: ValueError: Unable to determine SOCKS version 

Hi,

 I recently upgrade requests to 2.11.0 on centos 7 and keep getting this error when using it in a script:

```
File "/usr/local/lib/python2.7/dist-packages/github3/session.py", line 81, in request
    response = super(GitHubSession, self).request(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 475, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 596, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/adapters.py", line 390, in send
    conn = self.get_connection(request.url, proxies)
  File "/usr/local/lib/python2.7/dist-packages/requests/adapters.py", line 290, in get_connection
    proxy_manager = self.proxy_manager_for(proxy)
  File "/usr/local/lib/python2.7/dist-packages/requests/adapters.py", line 184, in proxy_manager_for
    **proxy_kwargs
  File "/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/contrib/socks.py", line 154, in __init__
    "Unable to determine SOCKS version from %s" % proxy_url
ValueError: Unable to determine SOCKS version from socks://http://username:password@someproxy.com:8080/
```

I tried to change my system socks proxy setting to this format, but still getting the same error with the updated proxy setting...

```
username:password@someproxy.com:8080/
```

So I downgraded requests to 2.10.0 and everything starts to working again. I repeated the this process on ubuntu 16 and got the same result. Can someone look into this please? 

Thanks,
Ryan


Ryan,

Do you have the ALL_PROXY environment variable set? If so, to what?


@Lukasa ~~No i dont, i will try and let you know~~
looks like its been auto set to this:

```
set | grep -i all_proxy
all_proxy=socks://http://user:password@someproxy.com:8080/
ALL_PROXY=socks://http://user:password@someproxy.com:8080/
```


@ryanym, does it work if you set the `all_proxy` scheme to `socks5` or `socks4`? Looking [here](https://github.com/kennethreitz/requests/blob/a2e41ba1f1ae81b2ed224030df908a1432ad435e/requests/packages/urllib3/contrib/socks.py#L153), seems like it's looking for the socks version. Unsure why you're getting different behavior between the two versions, though.

Edit: Did some more digging.

FWIW, it looks like part of the 2.11.0 release was to support all_proxy. So in 2.10.0, it didn't pick up the environment variable, all_proxy, and didn't bother using a proxy. In 2.11.0, it does, which causes the SOCKS version check, and the resulting error. 

I was able to get something to work by either setting all_proxy to `socks5://someproxy.com:someport` or sending the `proxies` dictionary (with the `all` key set to the same value as all_proxy environment variable) on the request.

Disclaimer: I'm a total n00b with the code base, just trying to help out. I would defer to @Lukasa for any real, competent help with this issue though :)


@shellhead, thanks for the reply, setting `all_proxy` sheme to `socks5` or `socks4` seems  gives me a timeout

```
File "/usr/local/lib/python2.7/dist-packages/github3/github.py", line 982, in organization
    json = self._json(self._get(url), 200)
  File "/usr/local/lib/python2.7/dist-packages/github3/models.py", line 130, in _get
    return self._session.get(url, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 488, in get
    return self.request('GET', url, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/github3/session.py", line 81, in request
    response = super(GitHubSession, self).request(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 475, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 596, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/adapters.py", line 423, in send
    timeout=timeout
  File "/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/connectionpool.py", line 595, in urlopen
    chunked=chunked)
  File "/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/connectionpool.py", line 352, in _make_request
    self._validate_conn(conn)
  File "/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/connectionpool.py", line 831, in _validate_conn
    conn.connect()
  File "/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/connection.py", line 254, in connect
    conn = self._new_conn()
  File "/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/contrib/socks.py", line 81, in _new_conn
    **extra_kw
  File "/usr/local/lib/python2.7/dist-packages/socks.py", line 195, in create_connection
    sock.connect((remote_host, remote_port))
  File "/usr/local/lib/python2.7/dist-packages/socks.py", line 747, in connect
    negotiate(self, dest_addr, dest_port)
  File "/usr/local/lib/python2.7/dist-packages/socks.py", line 598, in _negotiate_SOCKS4
    resp = self._readall(reader, 8)
  File "/usr/local/lib/python2.7/dist-packages/socks.py", line 268, in _readall
    d = file.read(count - len(data))
  File "/usr/lib/python2.7/socket.py", line 384, in read
    data = self._sock.recv(left)
KeyboardInterrupt
```


Out of curiosity, if you use something like `curl` using the socks proxy, do you get back a successful response? I ran the following, was able to see the request hit my socks proxy before forwarding going out.

``` sh
export all_proxy=socks5://someproxy:port
curl -v http://www.httpbin.org/headers
```

Is `all_proxy` set to `socks5://http://user:password@someproxy.com:8080/`; the `http://` in the middle seems like it doesn't belong. When I tried something in the same format, I get all sorts of errors.


I don't have the `http://` in the middle

```
ryan@vb:~$ export | grep -i all_proxy
declare -x all_proxy="socks5://user:pass@someproxy.com:8080/"
```

And for the curl test is successful as well. I am wondering does it have anything to do with the proxy itself?

```
ryan@vb:~$ curl -vvv http://www.httpbin.org/headers
*   Trying x.x.x.x....
* Connected to someproxy.com (x.x.x.x) port 8080 (#0)
* Proxy auth using Basic with user 'user'
> GET http://www.httpbin.org/headers HTTP/1.1
> Host: www.httpbin.org
> Proxy-Authorization: Basic xxxxxxxxxxxxxxxxxxxxxx
> User-Agent: curl/7.47.0
> Accept: */*
> Proxy-Connection: Keep-Alive
> 
< HTTP/1.1 200 OK
< Server: nginx
< Date: Thu, 25 Aug 2016 15:31:37 GMT
< Content-Type: application/json
< Content-Length: 189
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Credentials: true
< Proxy-Connection: Keep-Alive
< Connection: Keep-Alive
< Age: 0
< 
{
  "headers": {
    "Accept": "*/*", 
    "Cache-Control": "max-stale=0", 
    "Host": "www.httpbin.org", 
    "User-Agent": "curl/7.47.0", 
    "X-Bluecoat-Via": "8e7b0bc063e3ccb8"
  }
}
* Connection #0 to host someproxy.com left intact
```


Do you have a HTTP_PROXY environment variable around?


@Lukasa yes, i have `HTTP_PROXY, HTTPS_PROXY, http_proxy, https_proxy` set to `http://user:pass@someproxy.com:8080`


Yeah, so the current version of requests prefers ALL_PROXY to HTTP_PROXY. That's a bug fixed in master. 


@Lukasa I don't want to use any proxy settings.
r = requests.post(**\* , proxies=None) does not work.

It used to work few days ago. But problem started last night, which is failing my application.

What if I don't want to use any of the proxy configurations?

I tried os.environ.pop('http_proxy') and so on for each protocol. It didn't worked.
However, os.envron.pop('all_proxy') worked as it had the url : socks://***.

Any workaround?


Have you tried using `trust_env=False`?


hi
I am facing the same problem while using openstack keystone client . I have set the all_proxy as mentioned above. but unable to rectify the issue . i need some help .


@Rahul529 Sorry, what specific problem are you encountering?


@Lukasa , i have provided the error while the request is sent from python script .
Value Error : unable to determine the version SOCKS from socks://<ip>


We require that you provide the SOCKS url as either `socks4://` or `socks5://`


we can set by export all_proxy="socks5://<ip>:<port>"
after setting the request  goes into the infinite.  no response


Wondering if this might be better handled for the "socks://" case (as Ubuntu defaults to setting all_proxy to socks://). Currently this just outright fails unless you munge the environment variable (either by unsetting the environment variable, or munging it into socks5://). Wondering if treating socks:// as a SOCKS5 proxy may be a better approach? (I'm unsure if it makes sense to treat it as a SOCKS4 proxy, but I'd like to be corrected if there's a case for it).

Thanks!

@craigmaloney Well ultimately what's not clear to me is: what do *Ubuntu* mean with a scheme that just says `socks://`? A citation one way or the other would be really handy before we just leap in to make a call.

Unfortunately I'm not finding any clear-cut answer to that question. However I do know that Google Chrome and Firefox are able to cope with it. I took a quick peek in the Firefox source code to see what they do with it, but I'm not proficient enough in where things are to make heads or tails out of where it pulls the environment variable and determines what proxy version to try.

Yeah, so I'm absolutely willing to try to bring this into line with what others do, but I'd love to get some concrete citations on exactly what that is before we leap in.

May be you fill `socks` with `username:password@someproxy.com:8080/` in your network setting but chose `HTTPS` in shadowsocks , just leave `/etc/env` as what it is and leave socks as blank

I wrote a shell script as a work-around because I got tired of changing things by hand:

```
#!/bin/bash

export all_proxy=socks5://localhost:8080/
export ALL_PROXY=socks5://localhost:8080/
export socks_proxy=socks5://localhost:8080
```

It's not ideal, but it works.

It do work for some problems, but not for all, you still can not install some component.
I think it's a malfunction of proxy configuration.

I did a `sudo aptitude safe-upgrade` on Trisquel (to get something else working, which resolved that issue) and now I am encountering this issue.

When I run command I read in comment above, I get:
```
 set | grep -i socks_proxy
socks_proxy=socks://127.0.0.1:9050/
```

I do not know where the "set" file is that it is searching, but am I suppose to change it?

I tried simply reinstalling all the python libraries, but that did not seem to work. Any help is appreciated--thanks!