使用Google Colab连接到Jupyter笔记本电脑时出现“禁止”错误

时间:2020-08-24 06:31:35

标签: linux jupyter-notebook google-colaboratory

因此,我尝试按照以下Google的说明将Google Colab链接到安装在Linux(ubuntu)计算机上的Jupyter笔记本电脑:https://research.google.com/colaboratory/local-runtimes.html

笔记本服务器启动正常,但通过Google Colab连接到笔记本服务器时,连接失败,出现了“禁止”错误。

(base) my_user@sysmain:~$ jupyter notebook --NotebookApp.allow_origin='https://colab.research.google.com' --port=8888 --NotebookApp.port_retries=0 --no-browser
jupyter_http_over_ws extension initialized. Listening on /http_over_websocket
[I 23:01:03.636 NotebookApp] JupyterLab extension loaded from /home/my_user/miniconda3/lib/python3.8/site-packages/jupyterlab
[I 23:01:03.636 NotebookApp] JupyterLab application directory is /home/my_user/miniconda3/share/jupyter/lab
[I 23:01:03.638 NotebookApp] Serving notebooks from local directory: /home/my_user
[I 23:01:03.638 NotebookApp] Jupyter Notebook 6.1.3 is running at:
[I 23:01:03.638 NotebookApp] http://localhost:8888/
[I 23:01:03.638 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[I 23:01:20.212 NotebookApp] 302 GET / (127.0.0.1) 0.68ms
[I 23:01:20.214 NotebookApp] 302 GET /tree (127.0.0.1) 0.45ms
[W 23:01:20.240 NotebookApp] Forbidden
[W 23:01:20.240 NotebookApp] 403 GET /api/kernelspecs (127.0.0.1) 0.56ms referer=None
[I 23:01:22.273 NotebookApp] 302 GET / (127.0.0.1) 0.29ms
[I 23:01:22.274 NotebookApp] 302 GET /tree (127.0.0.1) 0.40ms
[W 23:01:22.278 NotebookApp] Forbidden
[W 23:01:22.278 NotebookApp] 403 GET /api/kernelspecs (127.0.0.1) 0.48ms referer=None

以前(https://github.com/googlecolab/colabtools/issues/162)上已有关于此主题的文章,但是添加--no-browser并不能解决问题,如您所输入的命令所见。

感谢您的帮助!

2 个答案:

答案 0 :(得分:0)

我在 ~/.jupyter/jupyter_notebook_config.py 中配置 jupyter 进行密码验证后遇到了这个问题。注释掉这些行

c.NotebookApp.password
c.NotebookApp.password_required

关闭密码并导致 Jupyter 使用基于令牌的身份验证。或者,如果您添加这样的一行

c.NotebookApp.token = 'yourTokenValue'

然后你可以通过 http://localhost:PORT/?token=yourTokenValue 连接

答案 1 :(得分:0)

注意您在 Google Colab 中复制到“本地连接设置”的网址。在本地运行 jupyter notebook 时,会打印如下输出:

[I 15:23:07.292 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 15:23:07.296 NotebookApp]

    To access the notebook, open this file in a browser:
        file:///Users/<your-username>/Library/Jupyter/runtime/nbserver-56791-open.html
    Or copy and paste one of these URLs:
        http://localhost:8888/?token=xyz....xyz
     or http://127.0.0.1:8888/?token=xyz....xyz

您应该复制此处显示的“确切”网址,即:

http://localhost:8888/?token=xyz....xyz

实际上,这里的 token 负责身份验证,这样您就不会再收到 403