jupyter-notebookremote-servervscode-remoteremote-development

problem with kernel creation in vscode while connected to remote jupyter server?


I am trying to connect to remote jupyter server which is running in remote server inside a docker. from vs code (local machine) with the help of jupyter extension, and running a newly created notebook. The problem seems to be the kernel creation via this method for this newly created notebook.

My Jupyter Server is running in remote server, inside a docker environment, with port forwarding enable. I can access it via my browser by http://{remote_machine_ip}:{port}/, and I am able to create new jupyter notebook. However when I use the vs code to open local notebook file, and connect to the remote jupyter server. When I try to run the cells, it shows the following error:

Failed to start the Kernel. 
'_xsrf' argument missing from POST. 
View Jupyter log for further details.

Possible solution However, if I try to open a new kernel in browser, and connect it to same kernel in vs code, the problem goes away.


Solution

  • This issue seems to be arising when vs code sends the request to create jupyter kernel to the jupyter server. As, when I tested with already running jupyter kernel in vs code, it works fine.

    The issue here is, security implementation of jupyter server, which don't allow cross site request to create a kernel, as it security vulnerability.

    For more details about _xsrf token, you can read here, although it doesn't talk about specific to jupyter server, its very easy to deduce the logic.

    In one post of jetbrains, I found the solution, to make jupyter ignore _xsrf token, by adding new flag while starting the jupyter server,

    --NotebookApp.disable_check_xsrf=True
    

    Or add it to your notebook config. Also, to make sure your request are not been blocked, as suggested by vscode blog. Add the following flag too,

    --NotebookApp.allow_origin='*'