python - Jupyter 笔记本 : "RuntimeError: Permissions assignment failed for secure file: ... Got ' 0o160 0' instead of ' 0o060 0' "

标签 python linux jupyter-notebook file-permissions

这个原帖在 super 用户发现here

我在我的计算机上为 RHEL 系统安装了 jupyter notebook,我使用命令 pip3 install --user jupyter 安装了它。后来由于它不工作pip3 install --force-reinstall --user jupyter ,所以知道我的 jupyter 文件存储在我的 ~/.local/bin 中目录。我不是我工作的集群的管理员或 super 用户,这就是我安装在 ~/.local/bin 中的原因.现在每当我启动一个 jupyter notebook 并打开一个 .ipynb 文件时,内核都会停留在“内核启动,请稍候...”直到内核刚刚退出。我试图看看浏览器是否影响了它,现在我已经在 Internet Explorer 11、Chrome 和 Edge 上尝试过,它们都做同样的事情。我不知道是什么导致内核无法加载。

编辑(2019 年 12 月 2 日):似乎有详细的可能解决方案 here但是,这些是描述如何在 Windows 系统上降级的解决方案,我在哪里运行基于 linux 的操作系统。

EDIT (03-DEC-2019):经过进一步调查,我发现 Jupyter 页面上的“内核正在启动,请稍候...”消息对应于终端回显:
RuntimeError: Permissions assignment failed for secure file: ':/path/to/user/tmp/jupyter-kernel:/path/to/user/jupyter-kernel/kernel-66b8b6e5-5e4c-4b05-98e9-870a5b431088.json'.Got '0o1600' instead of '0o0600'
这个问题好像在github issues page for Jupyter上讲过,我尝试按照规定去做,即更改 $JUPYTER_RUNTIME_DIR到一个新位置但没有用(我实际上尝试了不同的目录位置),我确保内核 .json 文件位于正确的位置和所有内容。我仍然继续遇到同样的错误。我的系统给我的 os.name 是 POSIX,所以我不知道这是否是潜在的问题,因为错误源自一个名为 path.py 的文件,并且似乎是 secure_write() 中的一个问题,这里有一部分代码:

@contextmanager
def secure_write(fname, binary=False):
    """Opens a file in the most restricted pattern available for
    writing content. This limits the file mode to `0o0600` and yields
    the resulting opened filed handle.

    Parameters
    ----------

    fname : unicode
        The path to the file to write

    binary: boolean
        Indicates that the file is binary
    """
    mode = 'wb' if binary else 'w'
    open_flag = os.O_CREAT | os.O_WRONLY | os.O_TRUNC
    try:
        os.remove(fname)
    except (IOError, OSError):
        # Skip any issues with the file not existing
        pass

    if os.name == 'nt':
        # Python on windows does not respect the group and public bits for chmod, so we need
        # to take additional steps to secure the contents.
        # Touch file pre-emptively to avoid editing permissions in open files in Windows
        fd = os.open(fname, os.O_CREAT | os.O_WRONLY | os.O_TRUNC, 0o0600)
        os.close(fd)
        open_flag = os.O_WRONLY | os.O_TRUNC
        win32_restrict_file_to_user(fname)

    with os.fdopen(os.open(fname, open_flag, 0o0600), mode) as f:
        if os.name != 'nt':
            # Enforce that the file got the requested permissions before writing
            file_mode = get_file_mode(fname)
            if 0o0600 != file_mode:
                raise RuntimeError("Permissions assignment failed for secure file: '{file}'."
                    "Got '{permissions}' instead of '0o0600'"
                    .format(file=fname, permissions=oct(file_mode)))
        yield f

最佳答案

一种解决方法 - 在 Jupyter 核心 v4.6.2 中,您现在可以设置环境变量 JUPYTER_ALLOW_INSECURE_WRITES1true , 禁用此检查

详情:https://discourse.jupyter.org/t/jupyter-core-4-6-2-release-with-insure-mode-option/3300

最后一个工作版本是 jupyter_client==5.3.1 , 在进行安全更改之前

关于python - Jupyter 笔记本 : "RuntimeError: Permissions assignment failed for secure file: ... Got ' 0o160 0' instead of ' 0o060 0' ",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59166173/

相关文章:

linux - 在 LinuxMint 中安装 Hadoop

jupyter-notebook - Anaconda/Jupyter 笔记本/500 : Internal Server Error/windows 10/python3

python - 无法在 Jupyter Notebook 中导入 tensorflow

python - 将相关矩阵转换为 pandas 中的 3 列数据框?

ruby - Capistrano 3 部署失败消息 - 退出状态 1(失败)

python - 使用 Gitlab 的 CI : QXcbConnection error 在 PyQt5 中自动化单元测试

linux - 在linux中为.net Core(Docker)编写txt文件

python - Jupyter 中的 Numpy 函数文档

python - 计算 Pandas 数据框中每一行的百分比

python - 如何合并 pandas 数据框中的 datetime.date 和 datetime.time 列?