code-server: MS Python: Failed to connect to Jupyter notebook.
Discussion migrated from https://github.com/cdr/code-server/issues/2341#issuecomment-796868354.
Under certain situations when running the MS Python extension, the following error can arise:
Failed to connect to Jupyter notebook. http://127.0.0.1:8889/ Error: Kernel Python 3 is not usable. Check the Jupyter output tab for more information.
This problem seems to have began for some users with code-server v3.9.
To view the Jupyter output tab, open the “Command Palette…” and type >Output: Focus on Output View. In the drop-down menu near the top right of the output window, select “Jupyter”.
I run into this bug with my particularly complicated setup, so I strongly suspect that others who see this problem will have a different manifestation.
I run code-server in a Docker container which is based on Ubuntu 20.04. Moreover, I don’t launch code-server directly, but I run it through JupyterLab via this plugin. It sets up a Jupyter proxy for the VS Code connection.
My suspicion is that something changed how the MS Python extension creates and connects with Jupyter kernels.
Looking at the Jupyter output, I see:
[I 19:41:19.033 NotebookApp] Serving notebooks from local directory: /home/jovyan/work
[I 19:41:19.034 NotebookApp] Jupyter Notebook 6.2.0 is running at:
[I 19:41:19.034 NotebookApp] http://127.0.0.1:8889/?token=...
[I 19:41:19.034 NotebookApp] or http://127.0.0.1:8889/?token=...
[I 19:41:19.034 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[W 19:41:19.048 NotebookApp] Forbidden
[W 19:41:19.048 NotebookApp] 403 GET /api/sessions?1615574479041 (127.0.0.1) 2.170000ms referer=None
[W 19:41:19.049 NotebookApp] Forbidden
[W 19:41:19.049 NotebookApp] 403 GET /api/kernelspecs?1615574479041 (127.0.0.1) 2.120000ms referer=None
[W 19:41:19.049 NotebookApp] 403 POST /api/contents/?1615574479042 (127.0.0.1): '_xsrf' argument missing from POST
[W 19:41:19.049 NotebookApp] '_xsrf' argument missing from POST
[W 19:41:19.050 NotebookApp] 403 POST /api/contents/?1615574479042 (127.0.0.1) 2.210000ms referer=None
[W 19:41:19.054 NotebookApp] Forbidden
[W 19:41:19.054 NotebookApp] 403 GET /api/sessions?1615574479049 (127.0.0.1) 1.500000ms referer=None
[W 19:41:19.055 NotebookApp] Forbidden
[W 19:41:19.055 NotebookApp] 403 GET /api/kernelspecs?1615574479049 (127.0.0.1) 1.810000ms referer=None
[W 19:41:19.056 NotebookApp] 403 POST /api/contents/?1615574479052 (127.0.0.1): '_xsrf' argument missing from POST
[W 19:41:19.056 NotebookApp] '_xsrf' argument missing from POST
[W 19:41:19.056 NotebookApp] 403 POST /api/contents/?1615574479052 (127.0.0.1) 0.810000ms referer=None
It seems that MS Python is trying to connect to my existing JupyterLab server, but it doesn’t know the correct token and is thus getting rejected.
I managed to fix it by adding the setting "python.dataScience.jupyterServerURI": "http://localhost:8888/?token=THEVALUEOFMYTOKEN", to my settings.json, or equivalently by changing the setting “Data Science: Jupyter Server URI” from local to http://localhost:8888/?token=THEVALUEOFMYTOKEN.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 21 (3 by maintainers)
@maresb thanks for going the extra mile helping out here! ♥️ We super appreciate it.
And sorry for all the trouble/workarounds you have to do @phisanti - hoping to get the Open VSX update out in the next month or two!
You are right. All that could be done was done, so I will wait for the open-vsx update. Thank you very much for your help, great to talk to you.
I suppose we can reopen this if someone else has this problem, but from my perspective this is solved.
So, you say that I need to run a command in the terminal like this before publish/build the image:
However, this is probably the result of me building the docker image based on youtube tutorials and cut-and-paste templates. I remember I tried to download the docker software in my computer and then build an image, but I end up nowhere. Then, I saw that it was possible to create an image only through writing something called a
DOCKERFILE. Thus, I copied the code-server docker image that paperspace uploaded to their github and made some changes (add CUDA and conda), which resulted in the code I sent previously. So, I discovered that I only need to link my docker account and, voilá, the image appeared in dockerhub. Since I am not using the terminal, then I guess you suggest to add a file calleddocker-compose.ymlto the github repository? If that is correct, then, I can do it right now. I will google how to organise the file and then add that line on the right spot.Once again, thank you @maresb for going the extra mile, I really feel you are trying to help me.
Hi @phisanti, my apologies if I came across as condescending. You should feel welcome regardless of your background or technical expertise, so I’m sorry if I failed there. It’s great that you’re learning Docker, and of course I was completely lost myself as I was a beginner.
I think I know more or less what the problem is, but I was missing some info I which I need to be able to help.
What I am missing is your
docker runcommand (or yourdocker-compose.ymlin case you are starting the container withdocker-compose). The-pis not forcode-serverbut ratherdocker run. So the command should look like:Could you send me the full
docker runcommand you’re using?By the way, the
EXPOSEcommand inDockerfileis effectively documentation; it doesn’t actually do anything. According to the documentationPersonally I find this weird, confusing and unexpected on Docker’s part. And as the documentation states, we need to figure out what’s going on with the
-pflags in yourdocker runcommand.To explain where I’m going with this, it looks to me like a Jupyter server is being started inside of your Docker container. Then code-server tries to connect to the Jupyter server from your browser. However, the Jupyter server is not running on your native OS, but inside your Docker container. Your browser is looking on your native OS and not finding anything, and thus giving an error.
My suspicion is that if you publish port 8889 (the port where your Jupyter server is starting) from Docker to your native OS, then your browser will be able to find the Jupyter server, and the error will go away.
Does this make sense? Let me know if anything I wrote was confusing.
I prepared the image like you did use docker. Then, build the machine in a remote machine on paperspace.com notebook, which uses port 8888 to push the vscode server to the browser. So you can install the image from https://hub.docker.com/repository/docker/phisanti/gradient-coder. The entry point is
/run.sh. Next, I just download and install ‘ms-python.python-2020.10.332292344’:Next, I will install the required python dependencies as I am asked. My final lib looks like:
Finally, I try to create a jupyter notebook, but I got the following error:
If I follow the advice of @maresb and I run jupyter lab from the terminal, then the following the response is:
If I click on the palette command the option to create a new jupyter notebook with the token of my notebook, then the error looks like:
If I use the token you posted, this is the error:
Failed to connect to remote Jupyter notebook. Check that the Jupyter Server URI setting has a valid running server specified. http://127.0.0.1:8889/lab Error: Kernel Python 3 is not usable. Check the Jupyter output tab for more information.
running on:
On a final note, when I install
ms-python.python-2020.3.69010, the problem seem to be gone. However, I cannot use widgets (I need nglview to display protein structures). So it seems to be an issue of that particular version with code-server or vscode.@jsjoeio thanks for being so eager to debug this issue! I have not been so forthcoming with details due to the complicated nature of my setup. (See the second paragraph which I added below the horizontal rule.) I hope this explains why I don’t explain how to reproduce, since that would involve setting up the Jupyter server proxy.
I recommend waiting for @phisanti to arrive and debugging his particular problem, since I suspect that his setup is more straightforward than mine. (Moreover, I have a solution for my particular case, so I opened this issue mainly for the benefit of him and those who also have this issue.)
My suspicion is that prior to code 3.9, MS Python was somehow proxying its own Jupyter server, but that from 3.9 the connection is no longer being proxied. But I don’t really know so many details.
@phisanti, my solution is very particular to the complicated configuration I’m running. The first step is to look at the output via the method I explained above.
In case you want to run your own Jupyter server, you can run
jupyter labfrom the command line to start JupyterLab. After JupyterLab starts, at the bottom of the terminal where you started JupyterLab you should see:You can take this URL
http://127.0.0.1:8889/lab?token=7ed6ea0f36651733bc695a24eae12700938f44556978b9aaand put it into your configuration. Then the MS Python extension will (hopefully) be able to connect to your Jupyter server.