zhangxaochen
zhangxaochen

Reputation: 34017

Anaconda ipython-notebook getting "UnicodeDecodeError: 'ascii' codec can't decode byte 0xb0 in position 1"

I installed Anaconda-1.9.1-Windows-x86.exe and tried to start ipython-notebook after installation. However I got such an error:

2014-03-15 17:00:48.724 [tornado.application] ERROR | Uncaught exception GET /st
atic/components/jquery-ui/themes/smoothness/jquery-ui.min.css (127.0.0.1)
HTTPRequest(protocol='http', host='127.0.0.1:8888', method='GET', uri='/static/c
omponents/jquery-ui/themes/smoothness/jquery-ui.min.css', version='HTTP/1.1', re
mote_ip='127.0.0.1', headers={'Accept-Language': 'zh-CN,zh;q=0.8', 'Accept-Encod
ing': 'gzip,deflate,sdch', 'Host': '127.0.0.1:8888', 'Accept': 'text/css,*/*;q=0
.1', 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTM
L, like Gecko) Chrome/24.0.1312.57 Safari/537.17 SE 2.X MetaSr 1.0', 'Accept-Cha
rset': 'GBK,utf-8;q=0.7,*;q=0.3', 'Connection': 'keep-alive', 'Referer': 'http:/
/127.0.0.1:8888/'})
Traceback (most recent call last):
  File "D:\Anaconda\lib\site-packages\tornado\web.py", line 1218, in _when_compl
ete
    callback()
  File "D:\Anaconda\lib\site-packages\tornado\web.py", line 1239, in _execute_me
thod
    self._when_complete(method(*self.path_args, **self.path_kwargs),
......
......
  File "D:\Anaconda\lib\mimetypes.py", line 258, in read_windows_registry
    for subkeyname in enum_types(hkcr):
  File "D:\Anaconda\lib\mimetypes.py", line 249, in enum_types
    ctype = ctype.encode(default_encoding) # omit in 3.x!
UnicodeDecodeError: 'ascii' codec can't decode byte 0xb0 in position 1: ordinal
not in range(128)
2014-03-15 17:00:50.220 [tornado.access] ERROR | 500 GET /static/tree/js/noteboo
klist.js (127.0.0.1) 98.00ms

Full traceback is here, I'm not sure what's happening.

I'm on win7 x64, and my last installation of anaconda 1.5.0 worked perfect. I'm guessing anaconda 1.9.1 may has some bugs dealing with unicode. Hope someone experienced could help ;). I'll have to downgrade now ;\

Upvotes: 3

Views: 6567

Answers (4)

razon
razon

Reputation: 4050

I solved problem by changing files:

  • \Anaconda2\Lib\ntpath.py:

result_path = result_path + p_path to

try:
    result_path = result_path + p_path
except UnicodeDecodeError:
    pass
  • \Anaconda2\Lib\site-packages\jupyter_core\paths.py

homedir = os.path.realpath(homedir) to

homedir = os.path.realpath(homedir).decode(sys.getfilesystemencoding())

and appdata = os.environ.get('APPDATA', None) to

appdata = os.environ.get('APPDATA', None).decode(sys.getfilesystemencoding())

  • \Anaconda2\Lib\site-packages\notebook\notebookapp.py

home = os.path.expanduser('~') to

home = os.path.expanduser('~').decode(sys.getfilesystemencoding())

Upvotes: 0

Frank Wang
Frank Wang

Reputation: 1610

in my case, the folder path contains a Chinese part which makes the same trouble.

Upvotes: 0

Andy White
Andy White

Reputation: 193

Knelson probably meant adding the following code on line 250 (which solved the problem for me):

                except UnicodeDecodeError:
                    pass

Not the UnicodeEncodeError

Upvotes: 0

knelson
knelson

Reputation: 93

This is a bug in mimetypes.py. Some program inserted a Unicode entry into the system registry and mimetypes is trying to decode it as ascii.

There is a patch, mentioned in this answer: UnicodeDecodeError : 'ascii' codec can't decode byte 0xe0 in position 0: ordinal not in range(128)

Here is a link to the actual patch itself: http://bugs.python.org/file18143/9291.patch

Assuming that your anaconda install is in the default place: C:\Anaconda, you can fix this issue quickly by opening a text editor and modifying C:\Anaconda\Lib\mimetypes.py by adding the following code on line 250:

                except UnicodeEncodeError:
                    pass

Upvotes: 4

Related Questions