nickagian
nickagian

Reputation: 663

Jupyter notebook: No connection to server because websocket connection fails

I have just installed Jupyter over pip (Python version is 3.7.2) in Windows 10, started the jupyter server by calling jupyter notebook, created a new notebook with kernel python3 in my web browser but a connection to the kernel is never achieved.

No obvious error in the command line:

C:\Users\xxxx>jupyter notebook
[I 21:18:21.005 NotebookApp] Serving notebooks from local directory: C:\Users\xxxx
[I 21:18:21.005 NotebookApp] The Jupyter Notebook is running at:
[I 21:18:21.006 NotebookApp] http://localhost:8888/?token=5743fcbbc805efa4b36c983a7beb63b95cf922957378d64f
[I 21:18:21.007 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 21:18:21.087 NotebookApp]

    To access the notebook, open this file in a browser:
        file:///C:/Users/xxxx/AppData/Roaming/jupyter/runtime/nbserver-18416-open.html
    Or copy and paste one of these URLs:
        http://localhost:8888/?token=5743fcbbc805efa4b36c983a7beb63b95cf922957378d64f
[I 21:18:33.777 NotebookApp] Creating new notebook in
[I 21:18:35.512 NotebookApp] Kernel started: ab30c1b3-55d2-45e9-9f01-b4bfc077bb01
[I 21:18:36.883 NotebookApp] Adapting to protocol v5.1 for kernel ab30c1b3-55d2-45e9-9f01-b4bfc077bb01
c:\users\xxxx\appdata\local\programs\python\python37-32\lib\site-packages\notebook\base\zmqhandlers.py:284: RuntimeWarning: coroutine 'WebSocketHandler.get' was never awaited
  super(AuthenticatedZMQStreamHandler, self).get(*args, **kwargs)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
[W 21:18:37.912 NotebookApp] Replacing stale connection: ab30c1b3-55d2-45e9-9f01-b4bfc077bb01:397de5420f9e4bce82d95967bf5fa1eb
[W 21:19:14.026 NotebookApp] 404 GET /static/components/preact/preact.min.js.map (::1) 18.98ms referer=None
[W 21:19:14.040 NotebookApp] 404 GET /static/components/preact-compat/preact-compat.min.js.map (::1) 6.49ms referer=None
[W 21:19:14.050 NotebookApp] 404 GET /static/components/proptypes/index.js.map (::1) 15.99ms referer=None
[I 21:20:36.067 NotebookApp] Saving file at /Untitled1.ipynb
[W 21:22:40.052 NotebookApp] Replacing stale connection: ab30c1b3-55d2-45e9-9f01-b4bfc077bb01:397de5420f9e4bce82d95967bf5fa1eb

I have tried all Chrome, Firefox and Microsoft Edge with no success. I even tried through PyCharm.

I then looked at the js console of the browser and seems that the problem is a failure in the websocket connection:

menubar.js:277 actions jupyter-notebook:find-and-replace does not exist, still binding it in case it will be defined later...
MenuBar.bind_events @ menubar.js:277
utils.js:60 load_extensions Arguments(1)
bidi.js:19 Loaded moment locale en
utils.js:37 Loading extension: jupyter-js-widgets/extension
session.js:54 Session: kernel_created (003a523b-3d40-41ac-b65e-154db92d5528)
kernel.js:459 Starting WebSockets: ws://localhost:8888/api/kernels/f8809bf9-988f-4666-b183-e01bed63fa76
kernel.js:461 WebSocket connection to 'ws://localhost:8888/api/kernels/f8809bf9-988f-4666-b183-e01bed63fa76/channels?session_id=e49c21f065e64e7a89847a0859d689dd' failed: Error during WebSocket handshake: Unexpected response code: 200
Kernel.start_channels @ kernel.js:461
kernel.js:103 Kernel: kernel_disconnected (f8809bf9-988f-4666-b183-e01bed63fa76)
kernel.js:544 WebSocket connection failed:  ws://localhost:8888/api/kernels/f8809bf9-988f-4666-b183-e01bed63fa76 true
kernel.js:562 Connection lost, reconnecting in 1 seconds.
kernel.js:103 Kernel: kernel_reconnecting (f8809bf9-988f-4666-b183-e01bed63fa76)
kernel.js:459 Starting WebSockets: ws://localhost:8888/api/kernels/f8809bf9-988f-4666-b183-e01bed63fa76

What could be the reason here?

Upvotes: 54

Views: 47370

Answers (8)

I resumed working with Jupyter notebook after a couple of years (and I think last time it was functional). After upgrading to solve a 500 : Internal Server Error, but without connecting to the kernel, what worked for me is (based on several references, some of which I am adding at the end)

> pip install --upgrade pyzmq
Requirement already satisfied: pyzmq in c:\users\user1\documents\appls_mydocs\development\anaconda3\lib\site-packages (17.0.0)
Collecting pyzmq
  Downloading pyzmq-25.1.2-cp36-cp36m-win_amd64.whl (1.2 MB)
     |¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦| 1.2 MB 234 kB/s
Installing collected packages: pyzmq
  Attempting uninstall: pyzmq
    Found existing installation: pyzmq 17.0.0
    Uninstalling pyzmq-17.0.0:
      Successfully uninstalled pyzmq-17.0.0
Successfully installed pyzmq-25.1.2

> pip install "tornado<6"
Collecting tornado<6
  Downloading tornado-5.1.1-cp36-cp36m-win_amd64.whl (455 kB)
     |¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦| 455 kB 226 kB/s
Installing collected packages: tornado
  Attempting uninstall: tornado
    Found existing installation: tornado 6.1
    Uninstalling tornado-6.1:
      Successfully uninstalled tornado-6.1
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
distributed 1.21.8 requires msgpack, which is not installed.
Successfully installed tornado-5.1.1

References:

  1. https://github.com/jupyter/notebook/issues/4437#issuecomment-468755424
  2. https://stackoverflow.com/a/56484803/2707864
  3. Cannot connect to Jupyter Notebook

Upvotes: 0

nikhil htks
nikhil htks

Reputation: 11

I have tried downgraded tornado and notebook it seems to be not working and unable to run cells on notebook

Found this work-around: Try downgrading Pyzmq.

pip install Pyzmq==19.0.2.

Upvotes: 1

Nikhil VJ
Nikhil VJ

Reputation: 6122

Don't downgrade tornado. Instead, force-reinstall jupyter.

pip3 install --force-reinstall --upgrade jupyter

Ref: https://github.com/jupyter/notebook/issues/4439

Upvotes: 6

Chinmay
Chinmay

Reputation: 128

This problem occurs when you install TensorFlow.js.

When you install TensorFlow.js, it also installs prompt-toolkit-1.0.14, which causes the problem.

After installing TensorFlow.js, you just have to install prompt-toolkit-3.0.5 to solve this problem by running the following code in your command prompt:

pip install prompt-toolkit==3.0.5

Upvotes: 0

JayaPrakash
JayaPrakash

Reputation: 11

Reset your jupyter notebook configuration file by use this below command to reset default config of jupyter_notebook_config.py

jupyter notebook --generate-config

Upvotes: 1

lmiguelvargasf
lmiguelvargasf

Reputation: 69923

The problem was that there was an incompatibility between the packages tornado 6 and notebook 5.7.4. notebook was updated on March 6th 2019 in order to solve this issue. Right now, the best way to solve it is the following:

Using pip

$ pip install -U jupyter

Using pipenv

$ pipenv update jupyter

Upvotes: 6

pylang
pylang

Reputation: 44545

The Jupyter Notebook 5.7.5 update should resolve issues with tornado 6. See the tweeted announcement and github release tag by the Jupyter team.

As of 03-06-19, both the docs and conda distribution are pending changes. You may however update using pip.


From the docs, upgrade with:

> pip install notebook --upgrade

Verify version:

> pip --version

Upvotes: 7

NicoWheat
NicoWheat

Reputation: 2441

I had the same problem, and following this vvk2001github https://github.com/jupyter/notebook/issues/4399 fixed it for me.

Uninstall tornado 6 and reinstall tornado 5.

sudo pip3 uninstall tornado
sudo pip3 install tornado==5.1.1

@kaleo gave this answer as well to similar question from @Jason Nichols

Upvotes: 98

Related Questions