1

In any browser under Windows7, I can not load ipython notebooks. I get the following error. I've tried in explorer, firefox and chrome. I get the same behavior with Enthought and Anaconda.

Ipython (no notebook works fine). Here is the end of the error trace:

ctype = ctype.encode(default_encoding) # omit in 3.x
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd7 in position 2: ordinal not in range(128)
2014-02-18 15:34:47.401 [tornado.access] ERROR | 500 GET /static/custom/custom.js (127.0.0.1) 145.00ms`

1 Answers1

1

The cause was identified in this answer.

But instead of

try:
    ctype = ctype.encode(default_encoding) # omit in 3.x!
except UnicodeEncodeError:
    pass

you may try, because it is a DecodeError after all:

try:
    ctype = ctype.encode(default_encoding) # omit in 3.x!
except UnicodeEncodeError, UnicodeDecodeError:
    pass

It is likely to happen in a multibyte encoding system. In this case, there is a mime type in registry contains multi-byte char. Python figured out it is an ascii string (which is wrong, that is why you see the ascii decode error) and tried to convert to Python's internal string representation before it actually do the encoding stuff. Then it sorrows with the UnicodeDecodeError exception. There is no UnicodeEncodeEorror yet at this point.

To make the whole internal process clear, you can explicitly convert ctype to unicode to make it continue to the encode stage, like

ctype = unicode(ctype, youractualencoding).encode(default_encoding)

Then it will (probably) throw the UnicodeEncodeError here, because the default_encoding is ascii in this scenario which cannot handle multi-byte character (This is also the reason it fails in the first place). So we need to handle both UnicodeEncodeError and UnicodeDecodeError.

Now you see what is going on here. IPython notebook was trying to load external resources like custom.js. It looks into the registry to find out the content type. Then it gets choked up by the exotic mime type.

Community
  • 1
  • 1
Joe Hong
  • 71
  • 2
  • I had the same problem as OP, thank's for the detailed explanation and link, but adding UnicodeDecodeError does not fix the issue, one has to delete the try/except block altogether, it is apparently useless. – gaborous Jun 23 '14 at 12:47