如何删除Jupyter笔记本的密码并重新设置令牌

2024-06-16 10:57:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我要为皮查姆做这个。

以下是我无法撤消的步骤。

  1. 我添加了用于身份验证的密码,使用:

    $ jupyter notebook password

  2. 然后我使用下面的命令对jupyter_notebook_config.py中的所有代码进行注释

    $ jupyter notebook --generate-config

  3. 然后我删除了jupyter_notebook_config.json中生成的哈希密码

    { "NotebookApp": { "password": "" } }

  4. 然后我在jupyter_notebook_config.py文件中执行了以下更改

    c.NotebookApp.password = ''
    c.NotebookApp.token = '< generated>'

  5. 现在,当我启动Jupyter笔记本时,没有生成令牌,也没有密码。

    Pycharm git:(master) ✗ jupyter notebook
    [I 21:53:35.158 NotebookApp] Serving notebooks from local directory: /Users/...
    [I 21:53:35.158 NotebookApp] 0 active kernels
    [I 21:53:35.158 NotebookApp] The Jupyter Notebook is running at:
    [I 21:53:35.158 NotebookApp] http://localhost:8888/?token=%3Cgenerated%3E

    Copy/paste this URL into your browser when you connect for the first time,
    to login with a token:
    http://localhost:8888/?token=%3Cgenerated%3E

现在,我该如何让它变得像以前那样,或者如何找回代币??

我甚至试过jupyter笔记本列表,但仍然有相同的URL。另外,我是在mac上做的,所以请给出相应的建议。


Tags: pytoken身份验证configlocalhosthttpurl密码
3条回答

嗯,我的配置看起来不一样。

只要删除这个文件,它就会默认地生成一个令牌

$ cat ~/.jupyter/jupyter_notebook_config.json
{
  "NotebookApp": {
    "password": "sha1:d0a89f391169:9ca771c3518f845438693b938b39703ce1104eaf"
  }

你不应该把<generated>直接放在那里。您应该放置一些生成的标记,例如f45cf5d6803b81bcd41bcfbf70130293bcf7a773feabe827

要生成自己的密码,请运行以下命令:

  • python3 -c 'import os;print(os.urandom(24).hex())'(在Linux/macOS上) 或者
  • py -c "import os;print(os.urandom(24).hex())"(在Windows上)

运行外壳:

ipython

from IPython.lib import passwd
passwd()

输入两次密码并复制“sha1:12345”代码。

之后,编辑jupyter配置文件:

vi ./jupyter/jupyter_notebook_config.py

。。。修改密码。

c.NotebookApp.password='sha1:12345'

粘贴你的“sha”代码并运行jupyter笔记本。

相关问题 更多 >