我有一个在 EMR 驱动程序节点上运行的工作 Jupyter 服务器,我可以在其中毫无问题地运行 python 和 pyspark 代码。当尝试让 VS Code Python 扩展连接到同一个 Jupyter 服务器时,出现以下错误:
Failed to connect to remote Jupyter notebook.
Check that the Jupyter Server URI setting has a valid running server specified.
http://***.***.***.***:8888/lab
Error: Invalid response: 405 Method Not Allowed
我按照 IBM 的这些说明在 EMR 集群上创建了自己的自签名证书。然后按照这些堆栈溢出说明链接到 GitHub 上的另一个用户将证书添加到 Chrome。
从 EMR 驱动节点的 bash 终端:
# create key and cert
openssl req -newkey rsa:2048 -nodes -keyout key.pem -x509 -days 365 -out certificate.pem
# combine key and cert
openssl pkcs12 -inkey key.pem -in certificate.pem -export -out certificate.p12
将
certificate.p12
下载到我的本地计算机,然后添加到 Chrome: chrome://settings/privacy
> 管理证书 > 导入 > 选择并导入 certificate.p12
> 重新启动 VS Code。
我仍然遇到同样的错误。
key.pem
和 certificate.pem
然后合并成证书吗?.pem
密钥吗?较新版本的 Jupyter 启动了类似于基于终端的
lynx
浏览器。
无论我选择哪个终端 shell,启动 Jupyter 后的输出都非常混乱,因为终端“浏览器”正在查看的“文档”与 Jupyter 服务器的输出混合在一起。
通过所有这些噪音,我可以使用箭头键和 enter 的某种组合以某种方式“导航”到以下位置,在该位置,以下内容与 Jupyter 输出混合显示在终端中的某处(通常突出显示,但取决于哪个)终端程序):
cookie: username-***-***-***-***-****=2|1:0|10:***********|27:username-***-***-***-***-****|44:***********************************k1ZmE=|****************************1bef31e Allow? (Y/N/Always/neVer)
我输入 A 并按 enter。
有时,有时不是,我会在终端中短暂看到以下内容:
Data transfer complete
然后我可以按 q 退出 Jupyter 启动的任何终端浏览器,只看到正常的 Jupyter 服务器输出。将完整 url 复制到 Jupyter 服务器,并将其粘贴到 VS Code Python 扩展
python.dataScience.jupyterServerURI
。
之后一切都按预期进行。
无需证书或密钥。