启动ipython-notebook时出现错误:未捕获的GET异常

1 投票
2 回答
4134 浏览
提问于 2025-04-18 12:41

在我的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"
}

完整的错误追踪信息在这里。我在网上搜索过,发现这篇帖子有类似的问题,但还是没能解决我的问题——文件mimetypes.py似乎被改动过。

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

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

改成:

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

但是没有成功。这个错误发生在我一个朋友的电脑上,所以很抱歉我无法重现这个问题并提供更多细节。

2 个回答

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
1

我刚遇到同样的问题,下面是我的解决方法:

问题的根源在于subkeyname这个变量包含了一个无法被_winreg.OpenKey函数读取的字符串。这可能是因为某些中文软件在注册表中添加了非Unicode的值(阿里旺旺是个主要嫌疑)。所以你需要捕捉这样的异常,并跳过它们。

以下是从第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

这个方法对我有效。希望对你有帮助。

撰写回答