danielfrg / pelican-jupyter

Pelican plugin for blogging with Jupyter/IPython Notebooks
Apache License 2.0
423 stars 105 forks source link

UnicodeDecodeError with Jupyter Notebooks Having Code Cells #49

Open sdsawtelle opened 8 years ago

sdsawtelle commented 8 years ago

I was using a python 2.7 virtualenv and the ipynb plugin for converting jupyter notebooks to html with pelican.

With some .ipynb notebooks (python 2.7 kernel) in the pelican content folder I tried running pelican content. I was receiving the error "UnicodeDecodeError: 'ascii' codec can't decade byte 0xc2 in position 333: ordinal not in range(128)." The error only occurred for jupyter notebooks that had code cells in them, the pure markdown notebooks were fine.

I found this SO question and added the following at the top of the pelicanconf.py file under from __future__ import __unicode_literals :

import sys reload(sys) sys.setdefaultencoding("utf-8")

This seems to have fixed the issue, but I don't really understand why.

Also sorry if this is the wrong place to be logging this. I'm a noob.

EDIT: added link to SO question.

dmmfll commented 8 years ago

I am having the same issue, I think.

ERROR: Could not process posts/object_classes/interfaces.ipynb | UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 87400: ordinal not in range(128)

@sdsawtelle solution fixed the problem for me, too. Thanks!

from __future__ import __unicode_literals

import sys
reload(sys)
sys.setdefaultencoding("utf-8")
cwithrow commented 8 years ago

Thank you so much for this, for some reason this issue never came up in my google searches, only when I combed the issues here directly (lesson learned).

MarkPlatts commented 5 years ago

Has there been any progress on this issue. I read elsewhere that the fix proposed by sdsawtelle is not recommended.