1

After installing anaconda 2.0.1 amd64 on my Windows7, I get the following error when starting 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"
}

The full traceback is here. I have searched on the Internet and find this post with similar problem, but still could not solve mine -- file mimetypes.py seems to have been changed.

I tried changing code in function enum_types in mimetypes.py:

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

to:

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

but of no luck. The error occurs on the PC of a friend of mine, so sorry for my not able to reproduce it and offer more details.

Community
  • 1
  • 1
zhangxaochen
  • 32,744
  • 15
  • 77
  • 108

2 Answers2

1

I just had the same problem and please see my workaround:

The problem behind is that subkeyname variable contains an unreadable string for _winreg.OpenKey function. It's probably due to some Chinese software adding non-unicode values to the registry (Ali-Wangwang a top suspect). So you need to catch such exceptions and just bypass them.

Here is the original code starting from line 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)

Simply add a "try:...except" block to get over the WindowsError exception:

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

This works for me. Hope it helps.

jeerrry
  • 11
  • 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
user2153553
  • 415
  • 4
  • 9