Jupyter Notebook cant connect to the server

I start the jupyter notebook server ok, but when I want to open the file MongoClient.ipynb I receive this error message in the browser:
A connection to the notebook server could not be established. The notebook will continue trying to reconnect. Check your network connection or notebook server configuration.

In the shell the logs are:

[I 10:09:45.220 NotebookApp] KernelRestarter: restarting kernel (4/5), new random ports
Traceback (most recent call last):
File “/usr/local/lib/python3.7/runpy.py”, line 193, in _run_module_as_main
main”, mod_spec)
File “/usr/local/lib/python3.7/runpy.py”, line 85, in _run_code
exec(code, run_globals)
File “/home/hache/Documents/Mongo-Python-Flask/mflix_venv/lib/python3.7/site-packages/ipykernel_launcher.py”, line 15, in
from ipykernel import kernelapp as app
File “/home/hache/Documents/Mongo-Python-Flask/mflix_venv/lib/python3.7/site-packages/ipykernel/init.py”, line 2, in
from .connect import *
File “/home/hache/Documents/Mongo-Python-Flask/mflix_venv/lib/python3.7/site-packages/ipykernel/connect.py”, line 13, in
from IPython.core.profiledir import ProfileDir
File “/home/hache/Documents/Mongo-Python-Flask/mflix_venv/lib/python3.7/site-packages/IPython/init.py”, line 55, in
from .terminal.embed import embed
File “/home/hache/Documents/Mongo-Python-Flask/mflix_venv/lib/python3.7/site-packages/IPython/terminal/embed.py”, line 16, in
from IPython.terminal.interactiveshell import TerminalInteractiveShell
File “/home/hache/Documents/Mongo-Python-Flask/mflix_venv/lib/python3.7/site-packages/IPython/terminal/interactiveshell.py”, line 20, in
from prompt_toolkit.formatted_text import PygmentsTokens
ModuleNotFoundError: No module named ‘prompt_toolkit.formatted_text’
[W 10:09:48.232 NotebookApp] KernelRestarter: restart failed
[W 10:09:48.232 NotebookApp] Kernel 5d4f3ccb-ca1f-4878-966a-df4c345e478a died, removing from map.

1 Like

I think this might be the key issue here:
ModuleNotFoundError: No module named ‘prompt_toolkit.formatted_text’
[W 10:09:48.232 NotebookApp] KernelRestarter: restart failed

Is your environment setup properly with all the required modules and python version?

Thank Austin.
I suppose that my virtual enviroment is ok. I import the requirements.txt to my venv, Im using python 3.7

I had the same problem.
Helped reinstallation of the toolkit module
(mflix_venv) …\mflix-python>pip uninstall prompt-toolkit
(mflix_venv) …\mflix-python>pip install prompt-toolkit

link:

2 Likes

Hello!

I am having the same issue, but the reinstalling is not helping…
What should I try next?
Here is the error I am getting:

    [I 13:37:15.144 NotebookApp] KernelRestarter: restarting kernel (4/5), new random ports
Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\ProgramData\Anaconda3\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\ProgramData\Anaconda3\lib\site-packages\ipykernel_launcher.py", line 15, in <module>
    from ipykernel import kernelapp as app
  File "C:\ProgramData\Anaconda3\lib\site-packages\ipykernel\__init__.py", line 2, in <module>
    from .connect import *
  File "C:\ProgramData\Anaconda3\lib\site-packages\ipykernel\connect.py", line 13, in <module>
    from IPython.core.profiledir import ProfileDir
  File "C:\ProgramData\Anaconda3\lib\site-packages\IPython\__init__.py", line 55, in <module>
    from .terminal.embed import embed
  File "C:\ProgramData\Anaconda3\lib\site-packages\IPython\terminal\embed.py", line 16, in <module>
    from IPython.terminal.interactiveshell import TerminalInteractiveShell
  File "C:\ProgramData\Anaconda3\lib\site-packages\IPython\terminal\interactiveshell.py", line 20, in <module>
    from prompt_toolkit.formatted_text import PygmentsTokens
ModuleNotFoundError: No module named 'prompt_toolkit.formatted_text'

I encountered the same issue and in my case the uninstall and reinstall of prompt-toolkit got things working. It looks like I had an older version of prompt-toolkit (1.0.15) which got uninstalled and which was on the reinstall replaced by a newer version (2.0.9).

This seemed to get the MongoClient notebook to work. During the reinstall I did get the message “jupyter-console 5.2.0 has requirement prompt-toolkit<2.0.0,>=1.0.0, but you’ll have prompt-toolkit 2.0.9 which is incompatible” but thus far this has not seemed to be an issue.

Full output from uninstall and reinstall:

(mflix) ➜  notebooks pip uninstall prompt-toolkit
Uninstalling prompt-toolkit-1.0.15:
  Would remove:
    /anaconda3/lib/python3.6/site-packages/prompt_toolkit-1.0.15.dist-info/*
    /anaconda3/lib/python3.6/site-packages/prompt_toolkit/*
Proceed (y/n)? y
  Successfully uninstalled prompt-toolkit-1.0.15
(mflix) ➜  notebooks pip install prompt-toolkit
Collecting prompt-toolkit
  Downloading https://files.pythonhosted.org/packages/f7/a7/9b1dd14ef45345f186ef69d175bdd2491c40ab1dfa4b2b3e4352df719ed7/prompt_toolkit-2.0.9-py3-none-any.whl (337kB)
    100% |████████████████████████████████| 337kB 1.9MB/s
Requirement already satisfied: six>=1.9.0 in /anaconda3/lib/python3.6/site-packages (from prompt-toolkit) (1.12.0)
Requirement already satisfied: wcwidth in /anaconda3/lib/python3.6/site-packages (from prompt-toolkit) (0.1.7)
jupyter-console 5.2.0 has requirement prompt-toolkit<2.0.0,>=1.0.0, but you'll have prompt-toolkit 2.0.9 which is incompatible.
Installing collected packages: prompt-toolkit
Successfully installed prompt-toolkit-2.0.9