我稍微编辑了http://jupyter.org/jupyter-js-services/页面中的示例代码,以便使用它来反应应用程序。
新内核已成功启动,但请求执行代码返回错误请求: 获取http://localhost/api/kernels/35b235a4-43e9-4452-8cdf-50e92299e7b4/channels?session_id=169c68adb049baaa196454929b152630 400(错误请求)
以下是代码:
`import { Kernel } from 'jupyter-js-services';
var xmlhttprequest = require('xmlhttprequest');
var ws = require('ws');
global.XMLHttpRequest = xmlhttprequest.XMLHttpRequest;
global.WebSocket = ws;
var ajaxSettings = {};
ajaxSettings['user'] = 'fakeuser';
ajaxSettings['password'] = '$apr1$4ZhnDsjP$YTj6gcQqyf0i4BMW4u028/';
// get info about the available kernels and start a new one
Kernel.getSpecs({ baseUrl: 'http://localhost' }).then(kernelSpecs => {
console.log('Default spec:', kernelSpecs.default);
console.log('Available specs',
Object.keys(kernelSpecs.kernelspecs));
// use the default name
var options = {
baseUrl: 'http://localhost',
wsUrl: 'ws://localhost',
name: kernelSpecs.default,
kernelName: 'python3',
notebookPath: 'try.ipynb',
ajaxSettings : ajaxSettings
}
Kernel.startNew(options).then((kernel) => {
console.log("CREATED NEW KERNEL: ", kernel);
var future = kernel.execute({ code: 'a = 1' } );
future.onDone = () => {
console.log('Future is fulfilled');
}
future.onIOPub = (msg) => {
console.log(msg.content); // rich output data
}
future.onStdin = (msg) => {
console.log(msg);
} });
});`
我将非常感谢任何帮助。
答案 0 :(得分:0)
通过编辑Nginx配置解决问题:
server {
listen 80;
location /api/ {
proxy_pass http://localhost:8888;
proxy_set_header Host $host;
# websocket support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 86400;
}
location /notebooks/ {
proxy_pass http://localhost:8888;
}
location /sockjs-node/ {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
location / {
proxy_pass http://localhost:3000;
}
}