Search code examples
pythonpython-3.xjupyter-notebookjupyterwerkzeug

'ASCII' encoding inside Jupyter notebook causing a BrokenFileSystemWarning


I started making a python3 werkzeug web application that is run from a linux server but every time I try to launch it from a Jupyter notebook, it displays this warning ( causing a 500 Internal Server Error in the browser )

from sys import getfilesystemencoding
print(getfilesystemencoding())  # Returns 'ascii' inside Jupyter

df = DataFrame(data=......mydata......)
webservice_test = WebService(lambda: globals(), 'df', host='XXX', port=XXX)

webservice_test.start()

/home/python/anaconda3/envs/notebook_env/lib/python3.5/site-packages/werkzeug/filesystem.py:63: BrokenFilesystemWarning: Detected a misconfigured UNIX filesystem: Will use UTF-8 as filesystem encoding instead of 'ascii'
  BrokenFilesystemWarning)

I tried disabling the warning but the web view breaks anyways ( the only difference is the warning is not displayed in Jupyter ). I found the encoding using the sys.getfilesystemencoding(), which returns 'ascii' every time it is run from Jupyter, but returns 'utf-8' when it is run on the same machine outside of Jupyter.

tl;dl Is there any way to change default encoding inside a Jupyter notebook?


Solution

  • After searching for a few hours, I found out that one function that should return formatted html returned a None Type, which is not encodable in utf-8, this caused the encoding error. The main problem was Werkzeug didn't specify on what line the error was.