Repository: conda/conda

Issue:
conda-4.4.0rc0 channel history can break conda
If the user has a private local repo or the Anaconda Repository and the hostname/ip changed or is no longer valid, conda will refuse to install any packages.

This happens even if you update your `.condarc` to only have the defaults channel again.

```
$ conda list --explicit
# This file may be used to create an environment using:
# $ conda create --name <env> --file <this file>
# platform: osx-64
@EXPLICIT
http://10.200.31.60:8081/conda/anaconda/osx-64/_license-1.1-py36_1.tar.bz2
https://repo.continuum.io/pkgs/free/osx-64/alabaster-0.7.10-py36_0.tar.bz2
https://repo.continuum.io/pkgs/free/osx-64/anaconda-custom-py36_0.tar.bz2
https://repo.continuum.io/pkgs/free/osx-64/anaconda-clean-1.1.0-py36_0.tar.bz2
https://repo.continuum.io/pkgs/free/osx-64/anaconda-client-1.6.3-py36_0.tar.bz2
https://repo.continuum.io/pkgs/free/osx-64/anaconda-navigator-1.6.3-py36_0.tar.bz2
https://repo.continuum.io/pkgs/free/osx-64/anaconda-project-0.6.0-py36_0.tar.bz2
https://repo.continuum.io/pkgs/free/osx-64/appnope-0.1.0-py36_0.tar.bz2
...
```
Note that one package was installed via a private repo that is no longer running from that IP address/hostname.

When attempting to install any other package from the defaults channel

```
$ conda install cx_oracle
Solving environment: failed

CondaHTTPError: HTTP 000 CONNECTION FAILED for url <http://10.200.31.60:8081/conda/anaconda/noarch/repodata.json>
Elapsed: -

An HTTP error occurred when trying to retrieve this URL.
HTTP errors are often intermittent, and a simple retry will get you on your way.
ConnectionError(MaxRetryError("HTTPConnectionPool(host='10.200.31.60', port=8081): Max retries exceeded with url: /conda/t/je-223eba05-93e2-42af-8024-606a6001e166/anaconda/noarch/repodata.json (Caused by NewConnectionError('<requests.packages.urllib3.connection.HTTPConnection object at 0x1031433c8>: Failed to establish a new connection: [Errno 61] Connection refused',))",),)
```

It appears that it is trying to contact the dead repo from that one package even if its no longer one of the channels in `.condarc`

Conda Config

```
channels:
  - defaults
ssl_verify: true
```


Discussion:
Hi @kalefranz - ran into a potentially similar issue... 

```
Microsoft Windows [Version 10.0.15063]
(c) 2017 Microsoft Corporation. All rights reserved.

C:\Users\skearns>conda install pykerberos
Solving environment: failed

CondaHTTPError: HTTP 401 UNAUTHORIZED for url <https://conda.anaconda.org/t/st-6b47489e-788e-4fff-865e-fd86234cb04a/qttesting/win-64/repodata.json>
Elapsed: 00:00.094663
CF-RAY: 39076a57ce81116b-DFW

The token 'st-6b47489e-788e-4fff-865e-fd86234cb04a' given for the URL is invalid.

If this token was pulled from anaconda-client, you will need to use
anaconda-client to reauthenticate.

If you supplied this token to conda directly, you will need to adjust your
conda configuration to proceed.

Use `conda config --show` to view your configuration's current state.
Further configuration help can be found at <https://conda.io/docs/config.html>.



C:\Users\skearns>
```
@DonMacleans [suggested](https://github.com/conda/conda/issues/4738#issuecomment-320945550)
`conda config --set ssl_verify no`
which seems to work for me to get past this `HTTP 000 CONNECTION FAILED`


Resolving patch:
diff --git a/conda/core/solve.py b/conda/core/solve.py
--- a/conda/core/solve.py
+++ b/conda/core/solve.py
@@ -449,13 +449,12 @@ def _prepare(self, prepared_specs):
             self._r = Resolve(self._index, channels=self.channels)
         else:
             # add in required channels that aren't explicitly given in the channels list
+            # For correctness, we should probably add to additional_channels any channel that
+            #  is given by PrefixData(self.prefix).all_subdir_urls().  However that causes
+            #  usability problems with bad / expired tokens.
+
             additional_channels = set()
-            # # TODO: probably necessary for correctness, but causes major issues with expired
-            # # tokens and channels that no longer exist
-            # additional_channels.update(
-            #     Channel(subdir_url) for subdir_url in PrefixData(self.prefix).all_subdir_urls()
-            # )
-            for spec in concatv(self.specs_to_remove, self.specs_to_add):
+            for spec in self.specs_to_add:
                 # TODO: correct handling for subdir isn't yet done
                 channel = spec.get_exact_value('channel')
                 if channel:


Test patch: