Repository: conda/conda

Issue:
Can not create a new conda environment/clean conda
I have just installed anaconda 4.2.0 on my system Ubuntu 16.04. As the default version of python is 3.5.2, i tried to create a new environment for Python 2.7 but it was impossible. I then tried to clean conda but this issue occured:

Current conda install:

               platform : linux-64
          conda version : 4.2.9
       conda is private : False
      conda-env version : 4.2.9
    conda-build version : 2.0.2
         python version : 3.5.2.final.0
       requests version : 2.11.1
       root environment : /home/huy/anaconda3  (writable)
    default environment : /home/huy/anaconda3
       envs directories : /home/huy/anaconda3/envs
          package cache : /home/huy/anaconda3/pkgs
           channel URLs : https://repo.continuum.io/pkgs/free/linux-64/
                          https://repo.continuum.io/pkgs/free/noarch/
                          https://repo.continuum.io/pkgs/pro/linux-64/
                          https://repo.continuum.io/pkgs/pro/noarch/
            config file : None
           offline mode : False



`$ /home/huy/anaconda3/bin/conda install anaconda-clean`




    Traceback (most recent call last):
      File "/home/huy/anaconda3/lib/python3.5/site-packages/conda/fetch.py", line 112, in fetch_repodata
        timeout=(3.05, 60))
      File "/home/huy/anaconda3/lib/python3.5/site-packages/requests/sessions.py", line 488, in get
        return self.request('GET', url, **kwargs)
      File "/home/huy/anaconda3/lib/python3.5/site-packages/requests/sessions.py", line 475, in request
        resp = self.send(prep, **send_kwargs)
      File "/home/huy/anaconda3/lib/python3.5/site-packages/requests/sessions.py", line 596, in send
        r = adapter.send(request, **kwargs)
      File "/home/huy/anaconda3/lib/python3.5/site-packages/requests/adapters.py", line 390, in send
        conn = self.get_connection(request.url, proxies)
      File "/home/huy/anaconda3/lib/python3.5/site-packages/requests/adapters.py", line 290, in get_connection
        proxy_manager = self.proxy_manager_for(proxy)
      File "/home/huy/anaconda3/lib/python3.5/site-packages/requests/adapters.py", line 184, in proxy_manager_for
        **proxy_kwargs
      File "/home/huy/anaconda3/lib/python3.5/site-packages/requests/adapters.py", line 43, in SOCKSProxyManager
        raise InvalidSchema("Missing dependencies for SOCKS support.")
    requests.exceptions.InvalidSchema: Missing dependencies for SOCKS support.
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/home/huy/anaconda3/lib/python3.5/site-packages/conda/fetch.py", line 287, in fetch_index
        repodatas = [(u, f.result()) for u, f in zip(urls, futures)]
      File "/home/huy/anaconda3/lib/python3.5/site-packages/conda/fetch.py", line 287, in <listcomp>
        repodatas = [(u, f.result()) for u, f in zip(urls, futures)]
      File "/home/huy/anaconda3/lib/python3.5/concurrent/futures/_base.py", line 405, in result
        return self.__get_result()
      File "/home/huy/anaconda3/lib/python3.5/concurrent/futures/_base.py", line 357, in __get_result
        raise self._exception
      File "/home/huy/anaconda3/lib/python3.5/concurrent/futures/thread.py", line 55, in run
        result = self.fn(*self.args, **self.kwargs)
      File "/home/huy/anaconda3/lib/python3.5/site-packages/conda/fetch.py", line 70, in func
        res = f(*args, **kwargs)
      File "/home/huy/anaconda3/lib/python3.5/site-packages/conda/fetch.py", line 137, in fetch_repodata
        .format(url, filename, e))
    conda.exceptions.CondaRuntimeError: Runtime error: Invalid index file: https://repo.continuum.io/pkgs/free/linux-64/repodata.json.bz2: Missing dependencies for SOCKS support.
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/home/huy/anaconda3/lib/python3.5/site-packages/conda/fetch.py", line 112, in fetch_repodata
        timeout=(3.05, 60))
      File "/home/huy/anaconda3/lib/python3.5/site-packages/requests/sessions.py", line 488, in get
        return self.request('GET', url, **kwargs)
      File "/home/huy/anaconda3/lib/python3.5/site-packages/requests/sessions.py", line 475, in request
        resp = self.send(prep, **send_kwargs)
      File "/home/huy/anaconda3/lib/python3.5/site-packages/requests/sessions.py", line 596, in send
        r = adapter.send(request, **kwargs)
      File "/home/huy/anaconda3/lib/python3.5/site-packages/requests/adapters.py", line 390, in send
        conn = self.get_connection(request.url, proxies)
      File "/home/huy/anaconda3/lib/python3.5/site-packages/requests/adapters.py", line 290, in get_connection
        proxy_manager = self.proxy_manager_for(proxy)
      File "/home/huy/anaconda3/lib/python3.5/site-packages/requests/adapters.py", line 184, in proxy_manager_for
        **proxy_kwargs
      File "/home/huy/anaconda3/lib/python3.5/site-packages/requests/adapters.py", line 43, in SOCKSProxyManager
        raise InvalidSchema("Missing dependencies for SOCKS support.")
    requests.exceptions.InvalidSchema: Missing dependencies for SOCKS support.
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/home/huy/anaconda3/lib/python3.5/site-packages/conda/exceptions.py", line 473, in conda_exception_handler
        return_value = func(*args, **kwargs)
      File "/home/huy/anaconda3/lib/python3.5/site-packages/conda/cli/main.py", line 144, in _main
        exit_code = args.func(args, p)
      File "/home/huy/anaconda3/lib/python3.5/site-packages/conda/cli/main_install.py", line 80, in execute
        install(args, parser, 'install')
      File "/home/huy/anaconda3/lib/python3.5/site-packages/conda/cli/install.py", line 238, in install
        prefix=prefix)
      File "/home/huy/anaconda3/lib/python3.5/site-packages/conda/api.py", line 24, in get_index
        index = fetch_index(channel_urls, use_cache=use_cache, unknown=unknown)
      File "/home/huy/anaconda3/lib/python3.5/site-packages/conda/fetch.py", line 293, in fetch_index
        for url in urls]
      File "/home/huy/anaconda3/lib/python3.5/site-packages/conda/fetch.py", line 293, in <listcomp>
        for url in urls]
      File "/home/huy/anaconda3/lib/python3.5/site-packages/conda/fetch.py", line 70, in func
        res = f(*args, **kwargs)
      File "/home/huy/anaconda3/lib/python3.5/site-packages/conda/fetch.py", line 137, in fetch_repodata
        .format(url, filename, e))
    conda.exceptions.CondaRuntimeError: Runtime error: Invalid index file: https://repo.continuum.io/pkgs/free/linux-64/repodata.json.bz2: Missing dependencies for SOCKS support.

What can I do to repair it?


Discussion:
@vovanhuy  Could you please share the output for:
`env | grep -i proxy`
I suspect that you are behind a (corporate?) http(s?)-proxy, but you have accidentally also added it as a socks proxy in the network configuration in Ubuntu, which also creates the environment variable:
SOCKS_PROXY
Yes, you are right. I added proxy for both http(s) and socks. However, when I tried to delete anaconda 4.2.0 and use 4.1.1, everything is ok.
Perhaps conda should provide a better error message/resolution. I had mentioned a fix/workaround for this in https://github.com/conda/conda/issues/3838.  Conda doesn't mention whether it officially supports SOCKS proxy at http://conda.pydata.org/docs/config.html#configure-conda-for-use-behind-a-proxy-server-proxy-servers . Perhaps the docs should explicitly mention that? Or, if it does support, then perhaps mention the order in which different types of proxies are checked.
    conda install pysocks

requests will use pysocks if it's available.  If you have environment configuration (either a .netrc file or environment variables) that instruct requests to use a socks proxy, then requests will complain if it's not installed.

Resolving patch:
diff --git a/conda/core/path_actions.py b/conda/core/path_actions.py
--- a/conda/core/path_actions.py
+++ b/conda/core/path_actions.py
@@ -221,7 +221,7 @@ def verify(self):
             # with max_retries = 2, max total time ~= 0.4 sec
             # with max_retries = 6, max total time ~= 6.5 sec
             count = self.transaction_context.get('_verify_backoff_count', 0)
-            max_retries = 6 if count < 2 else 2
+            max_retries = 6 if count < 4 else 3
             for n in range(max_retries):
                 sleep_time = ((2 ** n) + random()) * 0.1
                 log.trace("retrying lexists(%s) in %g sec", self.source_full_path, sleep_time)
diff --git a/conda/core/repodata.py b/conda/core/repodata.py
--- a/conda/core/repodata.py
+++ b/conda/core/repodata.py
@@ -17,7 +17,7 @@
 import warnings
 
 from requests import ConnectionError, HTTPError
-from requests.exceptions import SSLError
+from requests.exceptions import InvalidSchema, SSLError
 from requests.packages.urllib3.exceptions import InsecureRequestWarning
 
 from .. import CondaError, iteritems
@@ -26,11 +26,11 @@
 from .._vendor.auxlib.logz import stringify
 from ..base.constants import CONDA_HOMEPAGE_URL
 from ..base.context import context
-from ..common.compat import ensure_binary, ensure_text_type, ensure_unicode
+from ..common.compat import ensure_binary, ensure_text_type, ensure_unicode, text_type
 from ..common.url import join_url, maybe_unquote
 from ..connection import CondaSession
 from ..core.package_cache import PackageCache
-from ..exceptions import CondaHTTPError, CondaIndexError
+from ..exceptions import CondaDependencyError, CondaHTTPError, CondaIndexError
 from ..gateways.disk.delete import rm_rf
 from ..gateways.disk.update import touch
 from ..models.channel import Channel
@@ -154,9 +154,17 @@ def maybe_decompress(filename, resp_content):
         add_http_value_to_dict(resp, 'Last-Modified', fetched_repodata, '_mod')
         add_http_value_to_dict(resp, 'Cache-Control', fetched_repodata, '_cache_control')
         return fetched_repodata
-
-    except ValueError as e:
-        raise CondaIndexError("Invalid index file: {0}: {1}".format(join_url(url, filename), e))
+    except InvalidSchema as e:
+        if 'SOCKS' in text_type(e):
+            message = dals("""
+            Requests has identified that your current working environment is configured
+            to use a SOCKS proxy, but pysocks is not installed.  To proceed, remove your
+            proxy configuration, run `conda install pysocks`, and then you can re-enable
+            your proxy configuration.
+            """)
+            raise CondaDependencyError(message)
+        else:
+            raise
 
     except (ConnectionError, HTTPError, SSLError) as e:
         # status_code might not exist on SSLError
@@ -305,6 +313,9 @@ def maybe_decompress(filename, resp_content):
                              getattr(e.response, 'elapsed', None),
                              e.response)
 
+    except ValueError as e:
+        raise CondaIndexError("Invalid index file: {0}: {1}".format(join_url(url, filename), e))
+
 
 def write_pickled_repodata(cache_path, repodata):
     # Don't bother to pickle empty channels
diff --git a/conda/gateways/download.py b/conda/gateways/download.py
--- a/conda/gateways/download.py
+++ b/conda/gateways/download.py
@@ -7,14 +7,16 @@
 from threading import Lock
 import warnings
 
-from requests.exceptions import ConnectionError, HTTPError, SSLError
+from requests.exceptions import ConnectionError, HTTPError, InvalidSchema, SSLError
 
 from .. import CondaError
 from .._vendor.auxlib.ish import dals
 from .._vendor.auxlib.logz import stringify
 from ..base.context import context
+from ..common.compat import text_type
 from ..connection import CondaSession
-from ..exceptions import BasicClobberError, CondaHTTPError, MD5MismatchError, maybe_raise
+from ..exceptions import (BasicClobberError, CondaDependencyError, CondaHTTPError,
+                          MD5MismatchError, maybe_raise)
 
 log = getLogger(__name__)
 
@@ -116,6 +118,18 @@ def download(url, target_full_path, md5sum):
                       "trying again" % (url, digest_builder.hexdigest(), md5sum))
             raise MD5MismatchError(url, target_full_path, md5sum, actual_md5sum)
 
+    except InvalidSchema as e:
+        if 'SOCKS' in text_type(e):
+            message = dals("""
+                Requests has identified that your current working environment is configured
+                to use a SOCKS proxy, but pysocks is not installed.  To proceed, remove your
+                proxy configuration, run `conda install pysocks`, and then you can re-enable
+                your proxy configuration.
+                """)
+            raise CondaDependencyError(message)
+        else:
+            raise
+
     except (ConnectionError, HTTPError, SSLError) as e:
         help_message = dals("""
         An HTTP error occurred when trying to retrieve this URL.


Test patch: