Python 如何禁用 Jupyter 笔记本会话的密码请求?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41159797/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 00:29:39  来源:igfitidea点击:

How to disable password request for a Jupyter notebook session?

pythonipythonjupyter-notebookpython-3.5jupyter

提问by Salvatore Cosentino

I have been launching Jupyter Notebook for years using the following command:

多年来,我一直在使用以下命令启动 Jupyter Notebook:

jupyter-notebook --port=7000 --no-browser --no-mathjax

When I try to open the jupyter on the browser it ask me for a password, even though I have never set any before. It is important to note that If I do set the port to a value different than 7000 (eg., the default 8888)the interface will open with no problem

当我尝试在浏览器上打开 jupyter 时,它会要求我输入密码,即使我以前从未设置过密码。重要的是要注意,如果我确实将端口设置为7000 (eg., the default 8888)与接口不同的值,则将毫无问题地打开

I am running jupyter locally, and on the following setup:

我在本地运行 jupyter,并进行以下设置:

Python 3.5.2

With the following modules installed:

安装了以下模块:

jupyter (1.0.0), jupyter-client (4.4.0), jupyter-console (5.0.0), jupyter-core (4.2.1), ipykernel (4.5.2), ipython (5.1.0), ipython-genutils (0.1.0), nbconvert (4.3.0), nbformat (4.2.0), notebook (4.3.0)

NOTE: I have no jupyter configurations file

注意:我没有 jupyter 配置文件

Following are some of the output lines from the server:

以下是服务器的一些输出行:

[I 19:16:24.358 NotebookApp] Serving notebooks from local directory: /Users/my_user_name
[I 19:16:24.358 NotebookApp] 0 active kernels
[I 19:16:24.358 NotebookApp] The Jupyter Notebook is running at: http://localhost:7000/?token=aa0dab6e2d85766f3e2e4f0f6633e4473db56a56c94cac76
[I 19:16:24.358 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).

And follwing are messages after I try to open it on the browser (using port 7000)

以下是我尝试在浏览器上打开它后的消息(使用端口 7000)

[I 19:21:56.848 NotebookApp] 302 GET /tree (::1) 8.46ms
[D 19:21:56.857 NotebookApp] Using contents: services/contents
[D 19:21:56.919 NotebookApp] Path base/images/favicon.ico served from /usr/local/lib/python3.5/site-packages/notebook/static/base/images/favicon.ico
[D 19:21:56.920 NotebookApp] Path components/jquery-ui/themes/smoothness/jquery-ui.min.css served from /usr/local/lib/python3.5/site-packages/notebook/static/components/jquery-ui/themes/smoothness/jquery-ui.min.css
[D 19:21:56.922 NotebookApp] Path components/jquery-typeahead/dist/jquery.typeahead.min.css served from /usr/local/lib/python3.5/site-packages/notebook/static/components/jquery-typeahead/dist/jquery.typeahead.min.css
[D 19:21:56.923 NotebookApp] Path style/style.min.css served from /usr/local/lib/python3.5/site-packages/notebook/static/style/style.min.css
[D 19:21:56.925 NotebookApp] Path auth/css/override.css served from /usr/local/lib/python3.5/site-packages/notebook/static/auth/css/override.css
[D 19:21:56.926 NotebookApp] Path components/es6-promise/promise.min.js served from /usr/local/lib/python3.5/site-packages/notebook/static/components/es6-promise/promise.min.js
[D 19:21:56.926 NotebookApp] Path components/requirejs/require.js served from /usr/local/lib/python3.5/site-packages/notebook/static/components/requirejs/require.js
[D 19:21:56.933 NotebookApp] Path base/images/logo.png served from /usr/local/lib/python3.5/site-packages/notebook/static/base/images/logo.png
[D 19:21:56.934 NotebookApp] 200 GET /login?next=%2Ftree (::1) 80.86ms
[D 19:21:57.001 NotebookApp] Path custom.css served from /usr/local/lib/python3.5/site-packages/notebook/static/custom/custom.css
[D 19:21:57.003 NotebookApp] 304 GET /custom/custom.css (::1) 3.11ms
[D 19:21:57.341 NotebookApp] Path auth/js/main.min.js served from /usr/local/lib/python3.5/site-packages/notebook/static/auth/js/main.min.js
[D 19:21:57.344 NotebookApp] 200 GET /static/auth/js/main.min.js?v=20161219191623 (::1) 3.57ms

At this point there is a page from jupyter asking me to insert a password I have never set before.

此时有一个来自 jupyter 的页面要求我插入一个我以前从未设置过的密码。

SOLVED!

解决了!

With latest update of notebook module (4.3.1) the problem has been solved.

随着笔记本模块(4.3.1)的最新更新,问题已经解决。

Once the jupyter notebook is launched the user is prompted to paste a URL into the browser at the first connection:

启动 jupyter notebook 后,系统会提示用户在第一次连接时将 URL 粘贴到浏览器中:

Copy/paste this URL into your browser when you connect for the first time,
to login with a token:
    http://localhost:7000/?token=32be0f5ee74cfe521187bc479855ce8b9fbab9e8021701c9

This solved the problem!

这解决了问题!

回答by kowsalya

How to avoid "Invalid credentials" by disabling jupyter Notebook Password & Token

如何通过禁用 jupyter Notebook Password & Token 来避免“无效凭据”

First open Anaconda Prompt

首先打开Anaconda Prompt

  1. Enter the command jupyter notebook --generate-config
  1. 输入命令jupyter notebook --generate-config

enter image description here

在此处输入图片说明

  1. From jupyter directory ,edit the jupyter_notebook_config.py
  1. 从 jupyter 目录,编辑jupyter_notebook_config.py

made changes into the following command

对以下命令进行了更改

 c.NotebookApp.token = ''
 c.NotebookApp.password = u''
 c.NotebookApp.open_browser = True
 c.NotebookApp.ip = 'localhost'

Now launch the jupyter notebook from anaconda navigator definitely the problem will be resolved as soon..

现在从 anaconda navigator 启动 jupyter notebook肯定会尽快解决问题..

回答by okoethibm

Notebook 4.3.0 has enabled login security by default. The token to enter in the password field is printed in the output of the notebok server during startup (or can be included directly in the URL)

Notebook 4.3.0 默认开启了登录安全功能。在密码字段中输入的令牌在启动期间打印在笔记本服务器的输出中(或者可以直接包含在 URL 中)

The Jupyter Notebook is running at: http://0.0.0.0:8888/?token=f3e7fa23fb7e347ad05914368b625416b7a95a674dc078f7

See http://jupyter-notebook.readthedocs.io/en/latest/security.html#server-securityfor more info, including disabling the feature.

请参阅http://jupyter-notebook.readthedocs.io/en/latest/security.html#server-security了解更多信息,包括禁用该功能。

However, this would not explain why you get the password prompt when running on one port but not on another

但是,这并不能解释为什么在一个端口上运行而不是在另一个端口上运行时会收到密码提示

回答by tomkri

If you are trying to run from dockerwithout password just use CMDlike bellow:

如果您尝试在docker没有密码的情况下运行,请使用CMD如下所示:

CMD ["jupyter", "notebook", "--no-browser","--NotebookApp.token=''","--NotebookApp.password=''"]

回答by YjRtPya

The same issue occured on my machine since the last update of the jupyter-notebook package. After installing version

自上次更新 jupyter-notebook 软件包以来,我的机器上发生了同样的问题。安装版本后

jupyter-notebook-4.3.0-1-any.pkg.tar.xz

it prompted me for a password I never set. Downgradingto

它提示我输入一个我从未设置过的密码。 降级

jupyter-notebook-4.2.3-1-any.pkg.tar.xz

worked for me keeping the system a productive environment. Of course this is just a fast patch.

为我工作,使系统保持高效的环境。当然这只是一个快速补丁

I also wondered where the password was set since I don't have an explicit config file in my .jupyter-folder. Setting up my own with

我还想知道密码是在哪里设置的,因为我的.jupyter-folder 中没有明确的配置文件。设置我自己的

password_required=False

made no difference.

没有区别。

回答by Ranjita Shetty

You can first create a jupyter config file with:

您可以首先创建一个 jupyter 配置文件:

cd ~/.jupyter

cd ~/.jupyter

jupyter notebook --generate-config Then set the c.NotebookApp.token parameter to an empty string in the configuration file created

jupyter notebook --generate-config 然后在创建的配置文件中将c.NotebookApp.token参数设置为空字符串

c.NotebookApp.token = ''

c.NotebookApp.token = ''

As mentioned in comment, Setting to an empty string disables authentication altogether, which is NOT RECOMMENDED.

如评论中所述,设置为空字符串会完全禁用身份验证,这是不推荐的。

回答by lovecoding

Use the command jupyter notebook passwordto open jupyter & it asks to enter a new password.

使用该命令jupyter notebook password打开 jupyter 并要求输入新密码。

The hashed password is updated in the jupyter_notebook_config.jsonfile.

散列密码在jupyter_notebook_config.json文件中更新。

回答by wilma88

I solved the token authentication by replacing the password inside jupyter_notebook_config.jsonby running jupyter notebook passwordon the command line:

我通过在命令行上jupyter_notebook_config.json运行替换里面的密码解决了令牌认证jupyter notebook password

(base) C:\WINDOWS\system32>jupyter notebook list
http://localhost:8888/ :: C:\Users0089053
http://localhost:8889/ :: C:\Users0089053

(base) C:\WINDOWS\system32>jupyter notebook list
Enter password:
Verify password:
[NotebookPasswordApp] Wrote hashed password to C:\Users0089053\.jupyter\jupyter_notebook_config.json

回答by zappee

For me, the solutions described above was not applicable in Docker.

对我来说,上述解决方案不适用于 Docker。

The following solution works like a charm on Linux:

以下解决方案在 Linux 上就像一个魅力:

Details:

细节:

  • used image: tensorflow/tensorflow:latest-py3-jupyter
  • password I configured: 'password'
  • run Jupyter as a user (not root)
  • 使用的图像: tensorflow/tensorflow:latest-py3-jupyter
  • 我配置的密码:“密码”
  • 以用户(不是 root)身份运行 Jupyter

Steps to start Jupyter in Docker with your pre-defined password:

使用预定义密码在 Docker 中启动 Jupyter 的步骤:

  1. export JUPYTER_TOKEN='password'
  2. docker run -it --rm -p 8888:8888 -u $(id -u ${USER}):$(id -g ${USER}) -e JUPYTER_TOKEN=$JUPYTER_TOKEN -v /home/<user>/jupyter:/tf/ tensorflow/tensorflow:latest-py3-jupyter
  3. open http://localhost:8888and use 'password' as your password
  4. save password in ypur browser
  1. export JUPYTER_TOKEN='password'
  2. docker run -it --rm -p 8888:8888 -u $(id -u ${USER}):$(id -g ${USER}) -e JUPYTER_TOKEN=$JUPYTER_TOKEN -v /home/<user>/jupyter:/tf/ tensorflow/tensorflow:latest-py3-jupyter
  3. 打开http://localhost:8888并使用“password”作为密码
  4. 在ypur浏览器中保存密码

For me, that is the easiest way to get rid of the annoying token authentication.

对我来说,这是摆脱烦人的令牌身份验证的最简单方法。