简体   繁体   中英

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 ;\\

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

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

                except UnicodeDecodeError:
                    pass

Not the UnicodeEncodeError

在我的情况下,文件夹路径包含一个中国部分,同样的麻烦。

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())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM