Repository: conda/conda

Issue:
error while searching for `notebook`
I recently installed `ipykernel`, after which, commands
`ipython notebook` produced "ImportError: No module named 'notebook'", and
`jupyter notebook` produced "jupyter: 'notebook' is not a Jupyter command".
So, I ran `conda search notebook` and got the following message:

> Current conda install:

```
           platform : linux-64
      conda version : 4.2.9
   conda is private : False
  conda-env version : 4.2.9
conda-build version : 1.14.1
     python version : 3.4.5.final.0
   requests version : 2.9.1
   root environment : /usr1/eclark/anaconda3  (writable)
default environment : /usr1/eclark/anaconda3
   envs directories : /usr1/eclark/anaconda3/envs
      package cache : /usr1/eclark/anaconda3/pkgs
       channel URLs : https://conda.anaconda.org/anaconda/linux-64/
                      https://conda.anaconda.org/anaconda/noarch/
                      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 : /nfs/jet/home/eclark/.condarc
       offline mode : False
```

`$ /usr1/eclark/anaconda3/bin/conda search notebook`

```
Traceback (most recent call last):
  File "/usr1/eclark/anaconda3/lib/python3.4/site-packages/conda/exceptions.py", line 473, in conda_exception_handler
    return_value = func(*args, **kwargs)
  File "/usr1/eclark/anaconda3/lib/python3.4/site-packages/conda/cli/main.py", line 144, in _main
    exit_code = args.func(args, p)
  File "/usr1/eclark/anaconda3/lib/python3.4/site-packages/conda/cli/main_search.py", line 126, in execute
    execute_search(args, parser)
  File "/usr1/eclark/anaconda3/lib/python3.4/site-packages/conda/cli/main_search.py", line 268, in execute_search
    Channel(pkg.channel).canonical_name,
  File "/usr1/eclark/anaconda3/lib/python3.4/site-packages/conda/models/channel.py", line 44, in __call__
    elif value.endswith('.tar.bz2'):
TypeError: endswith first arg must be bytes or a tuple of bytes, not str
```

error while searching for `notebook`
I recently installed `ipykernel`, after which, commands
`ipython notebook` produced "ImportError: No module named 'notebook'", and
`jupyter notebook` produced "jupyter: 'notebook' is not a Jupyter command".
So, I ran `conda search notebook` and got the following message:

> Current conda install:

```
           platform : linux-64
      conda version : 4.2.9
   conda is private : False
  conda-env version : 4.2.9
conda-build version : 1.14.1
     python version : 3.4.5.final.0
   requests version : 2.9.1
   root environment : /usr1/eclark/anaconda3  (writable)
default environment : /usr1/eclark/anaconda3
   envs directories : /usr1/eclark/anaconda3/envs
      package cache : /usr1/eclark/anaconda3/pkgs
       channel URLs : https://conda.anaconda.org/anaconda/linux-64/
                      https://conda.anaconda.org/anaconda/noarch/
                      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 : /nfs/jet/home/eclark/.condarc
       offline mode : False
```

`$ /usr1/eclark/anaconda3/bin/conda search notebook`

```
Traceback (most recent call last):
  File "/usr1/eclark/anaconda3/lib/python3.4/site-packages/conda/exceptions.py", line 473, in conda_exception_handler
    return_value = func(*args, **kwargs)
  File "/usr1/eclark/anaconda3/lib/python3.4/site-packages/conda/cli/main.py", line 144, in _main
    exit_code = args.func(args, p)
  File "/usr1/eclark/anaconda3/lib/python3.4/site-packages/conda/cli/main_search.py", line 126, in execute
    execute_search(args, parser)
  File "/usr1/eclark/anaconda3/lib/python3.4/site-packages/conda/cli/main_search.py", line 268, in execute_search
    Channel(pkg.channel).canonical_name,
  File "/usr1/eclark/anaconda3/lib/python3.4/site-packages/conda/models/channel.py", line 44, in __call__
    elif value.endswith('.tar.bz2'):
TypeError: endswith first arg must be bytes or a tuple of bytes, not str
```



Discussion:

Resolving patch:
diff --git a/conda/models/channel.py b/conda/models/channel.py
--- a/conda/models/channel.py
+++ b/conda/models/channel.py
@@ -5,7 +5,7 @@
 from logging import getLogger
 from requests.packages.urllib3.util import Url
 
-from ..base.constants import DEFAULT_CHANNELS_UNIX, DEFAULT_CHANNELS_WIN
+from ..base.constants import DEFAULT_CHANNELS_UNIX, DEFAULT_CHANNELS_WIN, UTF8
 from ..base.context import context
 from ..common.compat import iteritems, odict, with_metaclass
 from ..common.url import (has_scheme, is_url, is_windows_path, join_url, on_win, path_to_url,
@@ -203,7 +203,9 @@ def from_channel_name(channel_name):
     def from_value(value):
         if value is None:
             return Channel(name="<unknown>")
-        elif has_scheme(value):
+        if hasattr(value, 'decode'):
+            value = value.decode(UTF8)
+        if has_scheme(value):
             if value.startswith('file:') and on_win:
                 value = value.replace('\\', '/')
             return Channel.from_url(value)


Test patch: