Repository: docker/docker-py

Issue:
requests 2.8.0 re-introduces bug #647



Discussion:
```
$ pip install -U 'requests<2.8.0'Collecting requests<2.8.0
  Using cached requests-2.7.0-py2.py3-none-any.whl
Installing collected packages: requests
  Found existing installation: requests 2.8.0
    Uninstalling requests-2.8.0:
      Successfully uninstalled requests-2.8.0
Successfully installed requests-2.7.0
$ py.test -k647 tests/integration/regression_test.py 
============================= test session starts ==============================
platform linux2 -- Python 2.7.9 -- py-1.4.30 -- pytest-2.7.2 -- /home/joffrey/.envs/pydocker/bin/python
rootdir: /home/joffrey/work/pydocker, inifile: pytest.ini
plugins: cov
collected 6 items 

tests/integration/regression_test.py::TestRegressions::test_647_support_doubleslash_in_image_names PASSED

======================== 5 tests deselected by '-k647' =========================
==================== 1 passed, 5 deselected in 0.07 seconds ====================
$ pip install -U 'requests==2.8.0'Collecting requests==2.8.0
  Using cached requests-2.8.0-py2.py3-none-any.whl
Installing collected packages: requests
  Found existing installation: requests 2.7.0
    Uninstalling requests-2.7.0:
      Successfully uninstalled requests-2.7.0
Successfully installed requests-2.8.0
(pydocker)joffrey@yuna:~/work/pydocker$ py.test -k647 tests/integration/regression_test.py 
============================= test session starts ==============================
platform linux2 -- Python 2.7.9 -- py-1.4.30 -- pytest-2.7.2 -- /home/joffrey/.envs/pydocker/bin/python
rootdir: /home/joffrey/work/pydocker, inifile: pytest.ini
plugins: cov
collected 6 items 

tests/integration/regression_test.py::TestRegressions::test_647_support_doubleslash_in_image_names FAILED

=================================== FAILURES ===================================
_________ TestRegressions.test_647_support_doubleslash_in_image_names __________
tests/integration/regression_test.py:30: in test_647_support_doubleslash_in_image_names
    self.client.inspect_image('gensokyo.jp//kirisame')
docker/utils/decorators.py:21: in wrapped
    return f(self, resource_id, *args, **kwargs)
docker/api/image.py:143: in inspect_image
    self._get(self._url("/images/{0}/json", image)), True
docker/client.py:110: in _get
    return self.get(url, **self._set_request_timeout(kwargs))
../../.envs/pydocker/local/lib/python2.7/site-packages/requests/sessions.py:483: in get
    return self.request('GET', url, **kwargs)
../../.envs/pydocker/local/lib/python2.7/site-packages/requests/sessions.py:471: in request
    resp = self.send(prep, **send_kwargs)
../../.envs/pydocker/local/lib/python2.7/site-packages/requests/sessions.py:600: in send
    history = [resp for resp in gen] if allow_redirects else []
../../.envs/pydocker/local/lib/python2.7/site-packages/requests/sessions.py:195: in resolve_redirects
    **adapter_kwargs
../../.envs/pydocker/local/lib/python2.7/site-packages/requests/sessions.py:579: in send
    r = adapter.send(request, **kwargs)
../../.envs/pydocker/local/lib/python2.7/site-packages/requests/adapters.py:339: in send
    url = self.request_url(request, proxies)
../../.envs/pydocker/local/lib/python2.7/site-packages/requests/adapters.py:278: in request_url
    proxy = select_proxy(request.url, proxies)
../../.envs/pydocker/local/lib/python2.7/site-packages/requests/utils.py:550: in select_proxy
    proxy = proxies.get(urlparts.scheme+'://'+urlparts.hostname)
E   TypeError: cannot concatenate 'str' and 'NoneType' objects
======================== 5 tests deselected by '-k647' =========================
==================== 1 failed, 5 deselected in 0.14 seconds ====================
```


Resolving patch:
diff --git a/docker/unixconn/unixconn.py b/docker/unixconn/unixconn.py
--- a/docker/unixconn/unixconn.py
+++ b/docker/unixconn/unixconn.py
@@ -73,12 +73,20 @@ def get_connection(self, url, proxies=None):
             if pool:
                 return pool
 
-            pool = UnixHTTPConnectionPool(url,
-                                          self.socket_path,
-                                          self.timeout)
+            pool = UnixHTTPConnectionPool(
+                url, self.socket_path, self.timeout
+            )
             self.pools[url] = pool
 
         return pool
 
+    def request_url(self, request, proxies):
+        # The select_proxy utility in requests errors out when the provided URL
+        # doesn't have a hostname, like is the case when using a UNIX socket.
+        # Since proxies are an irrelevant notion in the case of UNIX sockets
+        # anyway, we simply return the path URL directly.
+        # See also: https://github.com/docker/docker-py/issues/811
+        return request.path_url
+
     def close(self):
         self.pools.clear()


Test patch: