Jupyter Notebook 本机访问正常,局域网访问有登录界面,输入密码后空白 - 小众知识

Jupyter Notebook 本机访问正常,局域网访问有登录界面,输入密码后空白

2026-01-19 05:10:19 苏内容
  标签: Jupyter/Python
阅读:19

首先是配置jupyter notebook在局域网环境下使用:

jupyter notebook设置局域网环境下使用

jupyter notebook开启局域网使用权限后,终于可以使用平板在家里各个地方学习python啦!

开启方式

只需要三不即可开启局域网,分别是生成配置文件,设置密码和开启端口

1. 生成配置文件

命令行:

jupyter notebook --generate-config

2. 设置密码

命令行:

jupyter notebook password

3. 编辑配置文件

配置文件中添加如下配置:

c.NotebookApp.ip = '192.168.31.210'  # 本机ip
c.NotebookApp.port = 8888  # 端口
c.NotebookApp.open_browser = False   # 运行时不打开本机浏览器


设置完成后发现Jupyter Notebook  本机访问正常,局域网访问有登录界面,输入密码后空白


这是与 浏览器安全策略(跨域限制) 

核心修复:允许跨域与信任域名

当通过局域网 IP(如 192.168.x.x)访问时,浏览器会因安全限制阻止非 Localhost 的脚本运行。
  1. 生成配置文件(若已生成请跳过):
    jupyter notebook --generate-config
  2. 找到配置文件(通常在 C:\Users\用户名\.jupyter\jupyter_notebook_config.py)。
修改/添加以下关键参数
# 允许所有来源的跨域请求
c.NotebookApp.allow_origin = '*'
# 允许以 IP 形式访问
c.NotebookApp.ip = '0.0.0.0'
# 解决登录后空白的关键:信任生成的 HTML

c.NotebookApp.disable_check_xsrf = True

仍报错:

Uncaught exception GET /aext_core_server/feature_flag/init?1768804432477 (192.168.33.89)

    HTTPServerRequest(protocol='http', host='192.168.33.2:8888', method='GET', uri='/aext_core_server/feature_flag/init?1768804432477', version='HTTP/1.1', remote_ip='192.168.33.89')

    Traceback (most recent call last):

      File "D:\Program\anaconda3\Lib\site-packages\tornado\web.py", line 1848, in _execute

        result = await result

                 ^^^^^^^^^^^^

      File "D:\Program\anaconda3\Lib\site-packages\aext_core_server\handlers.py", line 40, in get

        [account, organizations, account_notebooks] = await asyncio.gather(

                                                      ^^^^^^^^^^^^^^^^^^^^^

        ...<3 lines>...

        )

        ^

      File "D:\Program\anaconda3\Lib\site-packages\aext_shared\handler.py", line 119, in anaconda_cloud_proxy

        user_access_credentials = await self.get_user_access_credentials(auth_optional=auth_optional)

                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

      File "D:\Program\anaconda3\Lib\site-packages\aext_shared\handler.py", line 96, in get_user_access_credentials

        raise e

      File "D:\Program\anaconda3\Lib\site-packages\aext_shared\handler.py", line 93, in get_user_access_credentials

        new_access_token, expires_in = await get_access_token(self.request)

                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

      File "D:\Program\anaconda3\Lib\site-packages\aext_shared\handler.py", line 182, in get_access_token

        raise UnauthorizedError({"reason": "missing refresh_token"})

    aext_shared.errors.UnauthorizedError: BackendError 403: missing refresh_token




方案一直接禁用报错的组件即可恢复界面,但是不起作用

# 禁用导致报错的 aext 扩展

jupyter server extension disable aext_core_server jupyter server extension disable aext_profile_manager_server


# 允许特定 IP 访问并信任其认证请求

c.ServerApp.allow_origin = '*'  

c.ServerApp.allow_remote_access = True

c.ServerApp.disable_check_xsrf = True  

# 核心:消除 403 权限拦截

c.ServerApp.cookie_options = {"SameSite": "None", "Secure": True}


扩展阅读
相关阅读
© CopyRight 2010-2021, PREDREAM.ORG, Inc.All Rights Reserved. 京ICP备13045924号-1