【问题标题】:'ASCII' encoding inside Jupyter notebook causing a BrokenFileSystemWarningJupyter 笔记本中的“ASCII”编码导致 BrokenFileSystemWarning
【发布时间】:2017-09-19 13:36:10
【问题描述】:

我开始制作一个从 linux 服务器运行的 python3 werkzeug web 应用程序,但是每次我尝试从 Jupyter 笔记本启动它时,它都会显示此警告(导致 500 Internal浏览器中的服务器错误

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)

我尝试禁用警告,但 Web 视图仍然中断(唯一的区别是警告未显示在 Jupyter 中)。我找到了编码 使用 sys.getfilesystemencoding(),每次从 Jupyter 运行时返回“ascii”,但在 Jupyter 之外的同一台机器上运行时返回“utf-8”。

tl;dl 有什么方法可以更改 Jupyter 笔记本中的默认编码?

【问题讨论】:

  • 顺便说一句,我在原始 wiki 和其他 stackoverflow 线程上尝试了一些建议,但没有任何帮助。
  • 我之前从未使用过 Jupyter notebook,我只有一个建议。尝试在 Python 文件的(第一)行中使用此表达式声明源文件的编码:# -*- coding: encoding -*- 其中 encoding 是所需的编码。
  • 我试过# -- coding: utf-8 -- 但好像对环境没有影响。

标签: python python-3.x jupyter-notebook jupyter werkzeug


【解决方案1】:

我也看到了BrokenFilesystemWarning: Detected a misconfigured UNIX filesystem 错误。挖完代码,发现这个错误是无害的,只是/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)

所以,我不会担心BrokenFilesystemWarning: Detected a misconfigured UNIX filesystem 警告。

【讨论】:

    【解决方案2】:

    找了几个小时,发现一个应该返回格式化html的函数返回了一个None Type,在utf-8中是不可编码的,这导致了编码错误。主要问题是 Werkzeug 没有指定错误发生在哪一行

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-11-20
      • 2017-12-04
      • 1970-01-01
      • 1970-01-01
      • 2017-05-05
      • 1970-01-01
      • 2021-12-31
      相关资源
      最近更新 更多