启动ipython-notebook时出现“ERROR:tornado.application:Uncaught exception GET”

时间:2014-07-09 18:29:18

标签: python ipython-notebook anaconda

在我的Windows7上安装anaconda 2.0.1 amd64后,启动ipython-notebook时出现以下错误:

ERROR:tornado.application:Uncaught exception GET /static/components/jquery-ui/th
emes/smoothness/jquery-ui.min.css?v=60f0405edd95e7135ec6a0bbc36d1385 (127.0.0.1)

HTTPRequest(protocol='http', host='localhost:8888', method='GET', uri='/static/c
omponents/jquery-ui/themes/smoothness/jquery-ui.min.css?v=60f0405edd95e7135ec6a0
bbc36d1385', version='HTTP/1.1', remote_ip='127.0.0.1', headers={'Accept-Languag
e': 'zh-CN,zh;q=0.8,en;q=0.6', 'Accept-Encoding': 'gzip,deflate,sdch', 'X-Forwar
ded-For': '211.166.224.142', 'Host': 'localhost:8888', 'Accept': 'text/css,*/*;q
=0.1', 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, li
ke Gecko) Chrome/33.0.1750.154 Safari/537.36', 'Connection': 'keep-alive', 'Refe
rer': 'http://localhost:8888/tree'})
Traceback (most recent call last):
  File "C:\Anaconda\lib\site-packages\tornado\web.py", line 1270, in _when_compl
ete
    callback()
  File "C:\Anaconda\lib\site-packages\tornado\web.py", line 1291, in _execute_me
thod
    self._when_complete(method(*self.path_args, **self.path_kwargs),
  File "C:\Anaconda\lib\site-packages\tornado\web.py", line 1954, in get
    self.set_headers()
  File "C:\Anaconda\lib\site-packages\tornado\web.py", line 2032, in set_headers

    content_type = self.get_content_type()
  File "C:\Anaconda\lib\site-packages\tornado\web.py", line 2210, in get_content
_type
    mime_type, encoding = mimetypes.guess_type(self.absolute_path)
  File "C:\Anaconda\lib\mimetypes.py", line 287, in guess_type
    init()
  File "C:\Anaconda\lib\mimetypes.py", line 348, in init
    db.read_windows_registry()
  File "C:\Anaconda\lib\mimetypes.py", line 256, in read_windows_registry
    with _winreg.OpenKey(hkcr, subkeyname) as subkey:
WindowsError: [Error 2]
ERROR:tornado.access:{
  "Accept-Language": "zh-CN,zh;q=0.8,en;q=0.6",
  "Accept-Encoding": "gzip,deflate,sdch",
  "X-Forwarded-For": "211.166.224.142",
  "Connection": "keep-alive",
  "Accept": "text/css,*/*;q=0.1",
  "User-Agent": "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Ge
cko) Chrome/33.0.1750.154 Safari/537.36",
  "Host": "localhost:8888",
  "Referer": "http://localhost:8888/tree"
}

完整的追溯is here。我在互联网上搜索并发现this post有类似的问题,但仍无法解决我的问题 - 文件mimetypes.py似乎已被更改。

我尝试更改enum_types中的函数mimetypes.py中的代码:

try:
    ctype = _winreg.EnumKey(mimedb, i)
except EnvironmentError:
    break

为:

try:
    ctype = _winreg.EnumKey(mimedb, i)
#except EnvironmentError:
#    break
finally:
    pass

但没有运气。该错误发生在我的朋友的PC上,很抱歉我无法重现它并提供更多细节。

2 个答案:

答案 0 :(得分:1)

我遇到了同样的问题,请看我的解决方法:

背后的问题是subkeyname变量包含_winreg.OpenKey函数的不可读字符串。这可能是由于一些中国软件将非unicode值添加到注册表中(Ali-Wangwang是最高的嫌疑人)。因此,您需要捕获此类异常并绕过它们。

以下是从第256行开始的原始代码:

with _winreg.OpenKey(hkcr, subkeyname) as subkey:
    # If there is no "Content Type" value, or if it is not
    # a simple string, simply skip
    try:
        mimetype, datatype = _winreg.QueryValueEx(
            subkey, 'Content Type')
    except EnvironmentError:
        continue
    if datatype != _winreg.REG_SZ:
        continue
    self.add_type(mimetype, subkeyname, strict)

只需添加“try:... except”块即可克服WindowsError异常:

try:
    with _winreg.OpenKey(hkcr, subkeyname) as subkey:
        # If there is no "Content Type" value, or if it is not
        # a simple string, simply skip
        try:
            mimetype, datatype = _winreg.QueryValueEx(
                subkey, 'Content Type')
        except EnvironmentError:
            continue
        if datatype != _winreg.REG_SZ:
            continue
        self.add_type(mimetype, subkeyname, strict)
except EnvironmentError:
    continue

这对我有用。希望它有所帮助。

答案 1 :(得分:0)

    def enum_types(mimedb):
        i = 0
        while True:
            try:
                ctype = _winreg.EnumKey(mimedb, i)
            except EnvironmentError:
                break
            else:
                if '\0' not in ctype: # add this line to mimetypes.py
                    yield ctype
            i += 1