问题
I am running a Django(Python 2.7) application with IPython notebook in a docker container and for some notebook, while accessing I am getting Error of An unknown error occurred while loading this notebook when I check logs it's showing
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/tornado/web.py", line 1415, in _execute
result = yield result
File "/usr/local/lib/python2.7/dist-packages/tornado/gen.py", line 870, in run
value = future.result()
File "/usr/local/lib/python2.7/dist-packages/tornado/concurrent.py", line 215, in result
raise_exc_info(self._exc_info)
File "/usr/local/lib/python2.7/dist-packages/tornado/gen.py", line 230, in wrapper
yielded = next(result)
File "/usr/local/lib/python2.7/dist-packages/notebook/services/contents/handlers.py", line 112, in get
path=path, type=type, format=format, content=content,
File "/usr/local/lib/python2.7/dist-packages/notebook/services/contents/filemanager.py", line 433, in get
model = self._notebook_model(path, content=content)
File "/usr/local/lib/python2.7/dist-packages/notebook/services/contents/filemanager.py", line 392, in _notebook_model
self.mark_trusted_cells(nb, path)
File "/usr/local/lib/python2.7/dist-packages/notebook/services/contents/manager.py", line 503, in mark_trusted_cells
trusted = self.notary.check_signature(nb)
File "/usr/local/lib/python2.7/dist-packages/nbformat/sign.py", line 438, in check_signature
signature = self.compute_signature(nb)
File "/usr/local/lib/python2.7/dist-packages/nbformat/sign.py", line 417, in compute_signature
for b in yield_everything(nb):
File "/usr/local/lib/python2.7/dist-packages/nbformat/sign.py", line 272, in yield_everything
for b in yield_everything(value):
File "/usr/local/lib/python2.7/dist-packages/nbformat/sign.py", line 276, in yield_everything
for b in yield_everything(element):
File "/usr/local/lib/python2.7/dist-packages/nbformat/sign.py", line 272, in yield_everything
for b in yield_everything(value):
File "/usr/local/lib/python2.7/dist-packages/nbformat/sign.py", line 276, in yield_everything
for b in yield_everything(element):
File "/usr/local/lib/python2.7/dist-packages/nbformat/sign.py", line 272, in yield_everything
for b in yield_everything(value):
File "/usr/local/lib/python2.7/dist-packages/nbformat/sign.py", line 272, in yield_everything
for b in yield_everything(value):
File "/usr/local/lib/python2.7/dist-packages/nbformat/sign.py", line 276, in yield_everything
for b in yield_everything(element):
File "/usr/local/lib/python2.7/dist-packages/nbformat/sign.py", line 281, in yield_everything
yield str(obj).encode('utf8')
UnicodeEncodeError: 'ascii' codec can't encode character u'\xd7' in position 14: ordinal not in range(128)
The same problem is happening when I am saving a file with the shape of the data frame Row X column problem was with the parsing of X(u'\xd7') Unicode.
Tried changing sys encoding noting happened
import sys
reload(sys)
sys.setdefaultencoding("utf-8")
回答1:
nbformat==5.0.x requires python 3.5+
Starting with 5.0, nbformat is now Python 3 only (>= 3.5)
https://nbformat.readthedocs.io/en/latest/changelog.html#id2
来源:https://stackoverflow.com/questions/59841253/unicodeencodeerror-ascii-codec-cant-encode-character-u-xd7-while-saving-a