jupyter notebook设置局域网环境下使用
jupyter notebook开启局域网使用权限后,终于可以使用平板在家里各个地方学习python啦!
只需要三不即可开启局域网,分别是生成配置文件,设置密码和开启端口
命令行:
jupyter notebook --generate-config
命令行:
jupyter notebook password
配置文件中添加如下配置:
c.NotebookApp.ip = '192.168.31.210' # 本机ip
c.NotebookApp.port = 8888 # 端口
c.NotebookApp.open_browser = False # 运行时不打开本机浏览器设置完成后发现Jupyter Notebook 本机访问正常,局域网访问有登录界面,输入密码后空白
这是与 浏览器安全策略(跨域限制)
核心修复:允许跨域与信任域名
192.168.x.x)访问时,浏览器会因安全限制阻止非 Localhost 的脚本运行。jupyter notebook --generate-configC:\Users\用户名\.jupyter\jupyter_notebook_config.py)。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}