Repository: conda/conda

Issue:
Unable to install package from anaconda.org
Despite successfully logging in, I am unable to install a package from anaconda.org. Why do I need to be "authorized" to install from a public repo?

Here's a session:

> (anaconda) src% conda install -c pydanny cookiecutter
> Fetching package metadata ...
> 
> CondaHTTPError: HTTP 401 UNAUTHORIZED for url <https://conda.anaconda.org/pydanny/linux-64/repodata.json>
> Elapsed: 00:00.186933
> CF-RAY: 34f70e302ebd099a-ORD
> 
> The remote server has indicated you are using invalid credentials for this channel.
> 
> If the remote site is anaconda.org or follows the Anaconda Server API, you
> will need to
>   (a) login to the site with `anaconda login`, or
>   (b) provide conda with a valid token directly.
> 
> Further configuration help can be found at <https://conda.io/docs/config.html>.
> 
> 
> 
> (anaconda) src% anaconda login
> Using Anaconda API: https://api.anaconda.org
> Username: smontanaro	
> smontanaro's Password: 
> login successful
> (anaconda) src% conda install -c pydanny cookiecutter
> Fetching package metadata ...
> 
> CondaHTTPError: HTTP 401 UNAUTHORIZED for url <https://conda.anaconda.org/t/sm-1bb26830-27a7-4652-a4df-f47d9426aaf1/pydanny/linux-64/repodata.json>
> Elapsed: 00:00.189228
> CF-RAY: 34f7135bfaa52597-ORD
> 
> The remote server has indicated you are using invalid credentials for this channel.
> 
> If the remote site is anaconda.org or follows the Anaconda Server API, you
> will need to
>   (a) login to the site with `anaconda login`, or
>   (b) provide conda with a valid token directly.
> 
> Further configuration help can be found at <https://conda.io/docs/config.html>.



Discussion:
Here's some verbose output.

> (anaconda) src% conda install --verbose -c pydanny cookiecutter
> Fetching package metadata ...An unexpected error has occurred.
> Please consider posting the following information to the
> conda GitHub issue tracker at:
> 
>     https://github.com/conda/conda/issues
> 
> 
> 
> overtaking stderr and stdout
> 
> stderr and stdout yielding back
> 
> Current conda install:
> 
>                platform : linux-64
>           conda version : 4.3.13
>        conda is private : False
>       conda-env version : 4.3.13
>     conda-build version : 2.1.5
>          python version : 3.6.0.final.0
>        requests version : 2.12.4
>        root environment : /home/skip/anaconda3  (writable)
>     default environment : /home/skip/anaconda3/envs/anaconda
>        envs directories : /home/skip/anaconda3/envs
>                           /home/skip/.conda/envs
>           package cache : /home/skip/anaconda3/pkgs
>                           /home/skip/.conda/pkgs
>            channel URLs : https://conda.anaconda.org/pydanny/linux-64
>                           https://conda.anaconda.org/pydanny/noarch
>                           https://repo.continuum.io/pkgs/free/linux-64
>                           https://repo.continuum.io/pkgs/free/noarch
>                           https://repo.continuum.io/pkgs/r/linux-64
>                           https://repo.continuum.io/pkgs/r/noarch
>                           https://repo.continuum.io/pkgs/pro/linux-64
>                           https://repo.continuum.io/pkgs/pro/noarch
>             config file : None
>            offline mode : False
>              user-agent : conda/4.3.13 requests/2.12.4 CPython/3.6.0 Linux/4.8.0-46-generic debian/stretch/sid glibc/2.24
>                 UID:GID : 1001:1001
> 
> 
> 
> `$ /home/skip/anaconda3/envs/anaconda/bin/conda install --verbose -c pydanny cookiecutter`
> 
> 
> 
> 
>     Traceback (most recent call last):
>       File "/home/skip/anaconda3/lib/python3.6/site-packages/conda/core/repodata.py", line 137, in fetch_repodata_remote_request
>         resp.raise_for_status()
>       File "/home/skip/anaconda3/lib/python3.6/site-packages/requests/models.py", line 893, in raise_for_status
>         raise HTTPError(http_error_msg, response=self)
>     requests.exceptions.HTTPError: 401 Client Error: UNAUTHORIZED for url: https://conda.anaconda.org/t/<TOKEN>/pydanny/linux-64/repodata.json
>     
>     During handling of the above exception, another exception occurred:
>     
>     Traceback (most recent call last):
>       File "/home/skip/anaconda3/lib/python3.6/site-packages/conda/exceptions.py", line 591, in conda_exception_handler
>         return_value = func(*args, **kwargs)
>       File "/home/skip/anaconda3/lib/python3.6/site-packages/conda/cli/main.py", line 134, in _main
>         exit_code = args.func(args, p)
>       File "/home/skip/anaconda3/lib/python3.6/site-packages/conda/cli/main_install.py", line 80, in execute
>         install(args, parser, 'install')
>       File "/home/skip/anaconda3/lib/python3.6/site-packages/conda/cli/install.py", line 222, in install
>         unknown=index_args['unknown'], prefix=prefix)
>       File "/home/skip/anaconda3/lib/python3.6/site-packages/conda/core/index.py", line 92, in get_index
>         index = fetch_index(channel_priority_map, use_cache=use_cache)
>       File "/home/skip/anaconda3/lib/python3.6/site-packages/conda/core/index.py", line 111, in fetch_index
>         repodatas = collect_all_repodata(use_cache, tasks)
>       File "/home/skip/anaconda3/lib/python3.6/site-packages/conda/core/repodata.py", line 70, in collect_all_repodata
>         repodatas = _collect_repodatas_serial(use_cache, tasks)
>       File "/home/skip/anaconda3/lib/python3.6/site-packages/conda/core/repodata.py", line 459, in _collect_repodatas_serial
>         for url, schan, pri in tasks]
>       File "/home/skip/anaconda3/lib/python3.6/site-packages/conda/core/repodata.py", line 459, in <listcomp>
>         for url, schan, pri in tasks]
>       File "/home/skip/anaconda3/lib/python3.6/site-packages/conda/core/repodata.py", line 105, in func
>         res = f(*args, **kwargs)
>       File "/home/skip/anaconda3/lib/python3.6/site-packages/conda/core/repodata.py", line 436, in fetch_repodata
>         mod_etag_headers.get('_mod'))
>       File "/home/skip/anaconda3/lib/python3.6/site-packages/conda/core/repodata.py", line 299, in fetch_repodata_remote_request
>         e.response)
>     conda.exceptions.CondaHTTPError: HTTP 401 UNAUTHORIZED for url <https://conda.anaconda.org/t/<TOKEN>/pydanny/linux-64/repodata.json>
>     Elapsed: 00:00.216415
>     CF-RAY: 34f7600708092525-ORD
>     
>     The remote server has indicated you are using invalid credentials for this channel.
>     
>     If the remote site is anaconda.org or follows the Anaconda Server API, you
>     will need to
>       (a) login to the site with `anaconda login`, or
>       (b) provide conda with a valid token directly.
>     
>     Further configuration help can be found at <https://conda.io/docs/config.html>.
> 
Fails when trying to install from conda-forge as well. I specifically listed public packages for linux-64:

> https://anaconda.org/search?q=access%3Apublic+platform%3Alinux-64+cookiecutter

but it still demands some authorization which I can't provide.

> (anaconda) ~% conda install -c conda-forge cookiecutter
> Fetching package metadata ...
> 
> CondaHTTPError: HTTP 401 UNAUTHORIZED for url <https://conda.anaconda.org/t/sm-1bb26830-27a7-4652-a4df-f47d9426aaf1/conda-forge/linux-64/repodata.json>
> Elapsed: 00:00.205895
> CF-RAY: 34f76f284a710994-ORD
> 
> The remote server has indicated you are using invalid credentials for this channel.
> 
> If the remote site is anaconda.org or follows the Anaconda Server API, you
> will need to
>   (a) login to the site with `anaconda login`, or
>   (b) provide conda with a valid token directly.
> 
> Further configuration help can be found at <https://conda.io/docs/config.html>.
> 
I just discovered this issue: https://github.com/conda/conda/issues/3399 Previous searching hadn't found it. (This ticket can likely be merged with that.)

Nothing which was suggested there worked for me. In fact, after executing

> (anaconda) ~% conda config --add channels conda-forge

even conda search commands failed. I had to --remove it before basic searches would work. Specifying any "non-standard" channel seems to fail.
If you have an expired token, anaconda.org will always return a 401.  `anaconda logout` is the quick fix to get rid of the expired token.  I guess we could add this extra information to that error message.

Resolving patch:
diff --git a/conda/core/repodata.py b/conda/core/repodata.py
--- a/conda/core/repodata.py
+++ b/conda/core/repodata.py
@@ -265,7 +265,8 @@ def maybe_decompress(filename, resp_content):
 
                 If the remote site is anaconda.org or follows the Anaconda Server API, you
                 will need to
-                  (a) login to the site with `anaconda login`, or
+                  (a) remove the invalid token from your system with `anaconda logout`, optionally
+                      followed by collecting a new token with `anaconda login`, or
                   (b) provide conda with a valid token directly.
 
                 Further configuration help can be found at <%s>.


Test patch: