Repository: conda/conda

Issue:
Cannot install packages after fresh install
Hi there,
I keep getting this error message, whenever I try to install any package after a fresh miniconda install.
Any help would be very much appreciated.
Thanks in advance!

--

Current conda install:

               platform : linux-64
          conda version : 4.2.12
       conda is private : False
      conda-env version : 4.2.12
    conda-build version : not installed
         python version : 3.5.2.final.0
       requests version : 2.11.1
       root environment : /home/pichama3/miniconda3  (writable)
    default environment : /home/pichama3/miniconda3
       envs directories : /home/pichama3/miniconda3/envs
          package cache : /home/pichama3/miniconda3/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/pichama3/miniconda3/bin/conda install snakemake`




    Traceback (most recent call last):
      File "/home/pichama3/miniconda3/lib/python3.5/site-packages/conda/exceptions.py", line 479, in conda_exception_handler
        return_value = func(*args, **kwargs)
      File "/home/pichama3/miniconda3/lib/python3.5/site-packages/conda/cli/main.py", line 145, in _main
        exit_code = args.func(args, p)
      File "/home/pichama3/miniconda3/lib/python3.5/site-packages/conda/cli/main_install.py", line 80, in execute
        install(args, parser, 'install')
      File "/home/pichama3/miniconda3/lib/python3.5/site-packages/conda/cli/install.py", line 238, in install
        prefix=prefix)
      File "/home/pichama3/miniconda3/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/pichama3/miniconda3/lib/python3.5/site-packages/conda/fetch.py", line 310, in fetch_index
        repodatas = [(u, f.result()) for u, f in zip(urls, futures)]
      File "/home/pichama3/miniconda3/lib/python3.5/site-packages/conda/fetch.py", line 310, in <listcomp>
        repodatas = [(u, f.result()) for u, f in zip(urls, futures)]
      File "/home/pichama3/miniconda3/lib/python3.5/concurrent/futures/_base.py", line 405, in result
        return self.__get_result()
      File "/home/pichama3/miniconda3/lib/python3.5/concurrent/futures/_base.py", line 357, in __get_result
        raise self._exception
      File "/home/pichama3/miniconda3/lib/python3.5/concurrent/futures/thread.py", line 55, in run
        result = self.fn(*self.args, **self.kwargs)
      File "/home/pichama3/miniconda3/lib/python3.5/site-packages/conda/fetch.py", line 74, in func
        res = f(*args, **kwargs)
      File "/home/pichama3/miniconda3/lib/python3.5/site-packages/conda/fetch.py", line 116, in fetch_repodata
        timeout=(3.05, 60))
      File "/home/pichama3/miniconda3/lib/python3.5/site-packages/requests/sessions.py", line 488, in get
        return self.request('GET', url, **kwargs)
      File "/home/pichama3/miniconda3/lib/python3.5/site-packages/requests/sessions.py", line 475, in request
        resp = self.send(prep, **send_kwargs)
      File "/home/pichama3/miniconda3/lib/python3.5/site-packages/requests/sessions.py", line 596, in send
        r = adapter.send(request, **kwargs)
      File "/home/pichama3/miniconda3/lib/python3.5/site-packages/requests/adapters.py", line 423, in send
        timeout=timeout
      File "/home/pichama3/miniconda3/lib/python3.5/site-packages/requests/packages/urllib3/connectionpool.py", line 589, in urlopen
        self._prepare_proxy(conn)
      File "/home/pichama3/miniconda3/lib/python3.5/site-packages/requests/packages/urllib3/connectionpool.py", line 797, in _prepare_proxy
        conn.connect()
      File "/home/pichama3/miniconda3/lib/python3.5/site-packages/requests/packages/urllib3/connection.py", line 254, in connect
        conn = self._new_conn()
      File "/home/pichama3/miniconda3/lib/python3.5/site-packages/requests/packages/urllib3/connection.py", line 142, in _new_conn
        (self.host, self.port), self.timeout, **extra_kw)
      File "/home/pichama3/miniconda3/lib/python3.5/site-packages/requests/packages/urllib3/util/connection.py", line 66, in create_connection
        if host.startswith('['):
    AttributeError: 'NoneType' object has no attribute 'startswith'



Discussion:
Probably an issue with requests, fixed with a requests update.
Reopened this ticket, because it's the first report of several duplicate issues.
From https://github.com/conda/conda/issues/4724#issuecomment-282239443:

> My bad. I'd managed to remove one of the forward slashes of the proxy in the .condarc file. (https:/ instead of https://)
For anyone having this issue, please investigate your proxy configuration.  Also if you find an error, report back on the details of where you configured in an error, so that we can help give conda better error messages in the future.
@kalefranz 
I tried print the proxies used at runtime, and got this:
**OrderedDict([('http', 'http://'), ('https', 'https://'), ('ftp', 'ftp://')])**
That proxies are from **requests.adapters:get_connection** function's parameter. Then the **select_proxy**  will select ('https', 'https://') as proxy, that's why no host in following steps.
I don't have any VPN enabled, and there's no proxy in Windows system when executing conda.

For now, I just add one statement in **HTTPSConnectionPool._new_conn** function to hide proxy, and it works: 

![image](https://user-images.githubusercontent.com/8531280/31279416-978988c8-aadb-11e7-877b-4e6206298ddc.png)

I think the proxies passed to requests.adapters may have some problems, but I don't have more time on debugging it. The no-proxy solution works fine for now, but it won't be final solution.
Following are my debug info, hope can do something useful

DEBUG conda.core.index:fetch_index(114): channel_urls=OrderedDict([('https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/win-64', ('https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free', 0)), ('https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/noarch', ('https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free', 0)), ('https://repo.continuum.io/pkgs/main/win-64', ('defaults', 1)), ('https://repo.continuum.io/pkgs/main/noarch', ('defaults', 1)), ('https://repo.continuum.io/pkgs/free/win-64', ('defaults', 2)), ('https://repo.continuum.io/pkgs/free/noarch', ('defaults', 2)), ('https://repo.continuum.io/pkgs/r/win-64', ('defaults', 3)), ('https://repo.continuum.io/pkgs/r/noarch', ('defaults', 3)), ('https://repo.continuum.io/pkgs/pro/win-64', ('defaults', 4)), ('https://repo.continuum.io/pkgs/pro/noarch', ('defaults', 4)), ('https://repo.continuum.io/pkgs/msys2/win-64', ('defaults', 5)), ('https://repo.continuum.io/pkgs/msys2/noarch', ('defaults', 5))])
Fetching package metadata ...DEBUG urllib3.util.retry:from_int(200): Converted retries value: 3 -> Retry(total=3, connect=None, read=None, redirect=None, status=None)
DEBUG conda.core.repodata:fetch_repodata(458): Locally invalidating cached repodata for https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/win-64 at C:\Users\Fox\Anaconda3\pkgs\cache\a2eb941d.json
DEBUG requests.utils:select_proxy(707):
        FOXADDED urlparts.hostname:mirrors.tuna.tsinghua.edu.cn
DEBUG requests.adapters:get_connection(302):
        FOXADDED url:https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/win-64/repodata.json proxy.host : https:// proxies:OrderedDict([('http', 'http://'), ('https', 'https://'), ('ftp', 'ftp://')])
DEBUG urllib3.poolmanager:connection_from_url(279):
        FOXADDED url->https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/win-64/repodata.json    host->mirrors.tuna.tsinghua.edu.cn    scheme->https
DEBUG urllib3.poolmanager:connection_from_host(217):
        FOXADDED host->mirrors.tuna.tsinghua.edu.cn
DEBUG urllib3.connectionpool:__init__(184):
        FOXADDED proxy.host : None
DEBUG requests.adapters:get_connection(313):
        FOXADDED conn.host->mirrors.tuna.tsinghua.edu.cn
DEBUG requests.utils:select_proxy(707):
        FOXADDED urlparts.hostname:mirrors.tuna.tsinghua.edu.cn
DEBUG requests.adapters:send(413):
        FOXADDED url->/anaconda/pkgs/free/win-64/repodata.json
DEBUG requests.adapters:send(414):
        FOXADDED conn.proxy->https://:443 conn.host->mirrors.tuna.tsinghua.edu.cn
DEBUG urllib3.connectionpool:_new_conn(827): Starting new HTTPS connection (1): mirrors.tuna.tsinghua.edu.cn
DEBUG urllib3.connection:__init__(222):
        FOXADDED --> 6  host: mirrors.tuna.tsinghua.edu.cn
DEBUG urllib3.connection:__init__(107):
        FOXADDED -->1
DEBUG urllib3.connection:set_cert(276):
        FOXADDED -->8  assert_hostname: None
DEBUG urllib3.connectionpool:urlopen(594):
        FOXADDED conn.host->mirrors.tuna.tsinghua.edu.cn
DEBUG urllib3.connection:connect(292):
        FOXADDED -->9 self.host: mirrors.tuna.tsinghua.edu.cn
DEBUG urllib3.connection:_new_conn(134):
        FOXADDED -->2  self.host: mirrors.tuna.tsinghua.edu.cn
DEBUG urllib3.connection:_match_hostname(366):
        FOXADDED -->10

Resolving patch:
diff --git a/conda/core/repodata.py b/conda/core/repodata.py
--- a/conda/core/repodata.py
+++ b/conda/core/repodata.py
@@ -18,7 +18,7 @@
 import warnings
 
 from requests import ConnectionError, HTTPError
-from requests.exceptions import InvalidSchema, SSLError
+from requests.exceptions import InvalidSchema, ProxyError as RequestsProxyError, SSLError
 from requests.packages.urllib3.exceptions import InsecureRequestWarning
 
 from .. import CondaError, iteritems
@@ -31,7 +31,7 @@
 from ..common.url import join_url, maybe_unquote
 from ..connection import CondaSession
 from ..core.package_cache import PackageCache
-from ..exceptions import CondaDependencyError, CondaHTTPError, CondaIndexError
+from ..exceptions import CondaDependencyError, CondaHTTPError, CondaIndexError, ProxyError
 from ..gateways.disk.delete import rm_rf
 from ..gateways.disk.update import touch
 from ..models.channel import Channel
@@ -160,6 +160,10 @@ 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 RequestsProxyError:
+        raise ProxyError()  # see #3962
+
     except InvalidSchema as e:
         if 'SOCKS' in text_type(e):
             message = dals("""
diff --git a/conda/exceptions.py b/conda/exceptions.py
--- a/conda/exceptions.py
+++ b/conda/exceptions.py
@@ -267,9 +267,14 @@ def __init__(self, message):
 
 
 class ProxyError(CondaError):
-    def __init__(self, message):
-        msg = '%s' % message
-        super(ProxyError, self).__init__(msg)
+    def __init__(self):
+        message = dals("""
+        Conda cannot proceed due to an error in your proxy configuration.
+        Check for typos and other configuration errors in any '.netrc' file in your home directory,
+        any environment variables ending in '_PROXY', and any other system-wide proxy
+        configuration settings.
+        """)
+        super(ProxyError, self).__init__(message)
 
 
 class CondaIOError(CondaError, IOError):
diff --git a/conda/gateways/download.py b/conda/gateways/download.py
--- a/conda/gateways/download.py
+++ b/conda/gateways/download.py
@@ -7,7 +7,8 @@
 from threading import Lock
 import warnings
 
-from requests.exceptions import ConnectionError, HTTPError, InvalidSchema, SSLError
+from requests.exceptions import (ConnectionError, HTTPError, InvalidSchema,
+                                 ProxyError as RequestsProxyError, SSLError)
 
 from .. import CondaError
 from .._vendor.auxlib.ish import dals
@@ -16,7 +17,7 @@
 from ..common.compat import text_type
 from ..connection import CondaSession
 from ..exceptions import (BasicClobberError, CondaDependencyError, CondaHTTPError,
-                          MD5MismatchError, maybe_raise)
+                          MD5MismatchError, maybe_raise, ProxyError)
 
 log = getLogger(__name__)
 
@@ -117,6 +118,8 @@ def download(url, target_full_path, md5sum):
             log.debug("MD5 sums mismatch for download: %s (%s != %s), "
                       "trying again" % (url, digest_builder.hexdigest(), md5sum))
             raise MD5MismatchError(url, target_full_path, md5sum, actual_md5sum)
+    except RequestsProxyError:
+        raise ProxyError()  # see #3962
 
     except InvalidSchema as e:
         if 'SOCKS' in text_type(e):


Test patch: