简体   繁体   English

Jupyter笔记本中的'ASCII'编码导致BrokenFileSystemWarning

[英]'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 ) 我开始制作从Linux服务器运行的python3 werkzeug Web应用程序 ,但是每次尝试从Jupyter笔记本启动时,它都会显示此警告(在浏览器中导致500 Internal Server Error

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 ). 我尝试禁用警告,但是Web视图仍然会中断(唯一的区别是警告未在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. 我发现使用sys.getfilesystemencoding()进行编码,每次从Jupyter运行时都会返回“ ascii”,但是在Jupyter之外的同一台计算机上运行时,返回“ utf-8”。

tl;dl Is there any way to change default encoding inside a Jupyter notebook? tl; dl是否有任何方法可以在Jupyter笔记本中更改默认编码?

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. 经过几个小时的搜索,我发现应该返回格式化html的一个函数返回了None类型 ,这在utf-8中是不可编码的,这导致了编码错误。 The main problem was Werkzeug didn't specify on what line the error was . 主要问题是Werkzeug 没有指定错误在哪一行

I saw the BrokenFilesystemWarning: Detected a misconfigured UNIX filesystem error too. 我看到了BrokenFilesystemWarning: Detected a misconfigured UNIX filesystem错误。 After digging the code, I saw that this error is harmless and just a warning in /usr/local/lib/python2.7/dist-packages/werkzeug/filesystem.py : 深入研究代码后,我发现此错误是无害的,只是/usr/local/lib/python2.7/dist-packages/werkzeug/filesystem.py的警告:

        warnings.warn(
            'Detected a misconfigured UNIX filesystem: Will use UTF-8 as '
            'filesystem encoding instead of {0!r}'.format(rv),
            BrokenFilesystemWarning)

So, I would not worry about the BrokenFilesystemWarning: Detected a misconfigured UNIX filesystem warning. 因此,我不必担心BrokenFilesystemWarning: Detected a misconfigured UNIX filesystem警告。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM