Stuck in "kernel status: initializing" with ipykernel

When I run the Jupyter Notebook I receive this error

    Traceback (most recent call last):
      File "/Users/sauron/opt/anaconda3/lib/python3.9/site-packages/tornado/web.py", line 1790, in _execute
        result = await result
      File "/Users/sauron/opt/anaconda3/lib/python3.9/site-packages/aext_assistant_server/handlers.py", line 117, in get
        raise HTTPError(403, reason="missing nucleus_token")
    tornado.web.HTTPError: HTTP 403: missing nucleus_token

When I try to connect to a kernel, this is what happens:

[W 2024-10-18 12:47:51.711 ServerApp] 403 GET /aext_assistant_server/nucleus_token?1729248471662 (49d96f76b13a4670871e77e5b7b97ba9@::1) 45.89ms referer=http://localhost:8891/notebooks/Desktop/OneDrive%20-%20Alma%20Mater%20Studiorum%20Universita%CC%80%20di%20Bologna/jupyter/pyvista.ipynb
[I 2024-10-18 12:48:00.170 ServerApp] Kernel started: bcf9d8d1-c27d-4c05-a7d3-b81dcf610395
[I 2024-10-18 12:48:00.195 ServerApp] Kernel shutdown: bcf9d8d1-c27d-4c05-a7d3-b81dcf610395
Fatal Python error: init_import_site: Failed to import the site module
Python runtime state: initialized
Traceback (most recent call last):
  File "/Users/sauron/opt/anaconda3/lib/python3.9/site.py", line 598, in <module>
    main()
  File "/Users/sauron/opt/anaconda3/lib/python3.9/site.py", line 585, in main
    known_paths = addsitepackages(known_paths)
  File "/Users/sauron/opt/anaconda3/lib/python3.9/site.py", line 368, in addsitepackages
    addsitedir(sitedir, known_paths)
  File "/Users/sauron/opt/anaconda3/lib/python3.9/site.py", line 217, in addsitedir
    addpackage(sitedir, name, known_paths)
  File "/Users/sauron/opt/anaconda3/lib/python3.9/site.py", line 177, in addpackage
    exec(line)
  File "<string>", line 1, in <module>
  File "/Users/sauron/opt/anaconda3/lib/python3.9/importlib/util.py", line 2, in <module>
    from . import abc
  File "/Users/sauron/opt/anaconda3/lib/python3.9/importlib/abc.py", line 17, in <module>
    from typing import Protocol, runtime_checkable
  File "/Users/sauron/opt/anaconda3/lib/python3.9/typing.py", line 2085, in <module>
    class IO(Generic[AnyStr]):
  File "/Users/sauron/opt/anaconda3/lib/python3.9/typing.py", line 2144, in IO
    def readlines(self, hint: int = -1) -> List[AnyStr]:
  File "/Users/sauron/opt/anaconda3/lib/python3.9/typing.py", line 274, in inner
    return cached(*args, **kwds)
  File "/Users/sauron/opt/anaconda3/lib/python3.9/typing.py", line 837, in __getitem__
    params = tuple(_type_check(p, msg) for p in params)
KeyboardInterrupt
[W 2024-10-18 12:49:00.199 ServerApp] Timeout waiting for kernel_info reply from bcf9d8d1-c27d-4c05-a7d3-b81dcf610395
[W 2024-10-18 12:49:00.200 ServerApp] Timeout waiting for kernel_info reply from bcf9d8d1-c27d-4c05-a7d3-b81dcf610395
[E 2024-10-18 12:49:00.201 ServerApp] Uncaught exception GET /api/kernels/bcf9d8d1-c27d-4c05-a7d3-b81dcf610395/channels?session_id=b19d9123-f9cf-4f8a-9c9b-343886ad0cce (::1)
    HTTPServerRequest(protocol='http', host='localhost:8891', method='GET', uri='/api/kernels/bcf9d8d1-c27d-4c05-a7d3-b81dcf610395/channels?session_id=b19d9123-f9cf-4f8a-9c9b-343886ad0cce', version='HTTP/1.1', remote_ip='::1')
    Traceback (most recent call last):
      File "/Users/sauron/opt/anaconda3/lib/python3.9/site-packages/tornado/web.py", line 1790, in _execute
        result = await result
      File "/Users/sauron/opt/anaconda3/lib/python3.9/site-packages/jupyter_server/services/kernels/websocket.py", line 66, in get
        await super().get(kernel_id=kernel_id)
      File "/Users/sauron/opt/anaconda3/lib/python3.9/site-packages/tornado/websocket.py", line 273, in get
        await self.ws_connection.accept_connection(self)
      File "/Users/sauron/opt/anaconda3/lib/python3.9/site-packages/tornado/websocket.py", line 863, in accept_connection
        await self._accept_connection(handler)
      File "/Users/sauron/opt/anaconda3/lib/python3.9/site-packages/tornado/websocket.py", line 903, in _accept_connection
        self.selected_subprotocol = handler.select_subprotocol(subprotocols)
      File "/Users/sauron/opt/anaconda3/lib/python3.9/site-packages/jupyter_server/services/kernels/websocket.py", line 88, in select_subprotocol
        preferred_protocol = self.connection.kernel_ws_protocol
    AttributeError: 'NoneType' object has no attribute 'kernel_ws_protocol'
[E 2024-10-18 12:49:00.233 ServerApp] {
      "Host": "localhost:8891",
      "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6.1 Safari/605.1.15"
    }
[E 2024-10-18 12:49:00.233 ServerApp] 500 GET /api/kernels/bcf9d8d1-c27d-4c05-a7d3-b81dcf610395/channels?session_id=b19d9123-f9cf-4f8a-9c9b-343886ad0cce (49d96f76b13a4670871e77e5b7b97ba9@::1) 60045.30ms referer=None
[E 2024-10-18 12:49:00.234 ServerApp] Uncaught exception GET /api/kernels/bcf9d8d1-c27d-4c05-a7d3-b81dcf610395/channels?session_id=885fd6fd-7eac-457b-8555-ba9721602f09 (::1)
    HTTPServerRequest(protocol='http', host='localhost:8891', method='GET', uri='/api/kernels/bcf9d8d1-c27d-4c05-a7d3-b81dcf610395/channels?session_id=885fd6fd-7eac-457b-8555-ba9721602f09', version='HTTP/1.1', remote_ip='::1')
    Traceback (most recent call last):
      File "/Users/sauron/opt/anaconda3/lib/python3.9/site-packages/tornado/web.py", line 1790, in _execute
        result = await result
      File "/Users/sauron/opt/anaconda3/lib/python3.9/site-packages/jupyter_server/services/kernels/websocket.py", line 66, in get
        await super().get(kernel_id=kernel_id)
      File "/Users/sauron/opt/anaconda3/lib/python3.9/site-packages/tornado/websocket.py", line 273, in get
        await self.ws_connection.accept_connection(self)
      File "/Users/sauron/opt/anaconda3/lib/python3.9/site-packages/tornado/websocket.py", line 863, in accept_connection
        await self._accept_connection(handler)
      File "/Users/sauron/opt/anaconda3/lib/python3.9/site-packages/tornado/websocket.py", line 903, in _accept_connection
        self.selected_subprotocol = handler.select_subprotocol(subprotocols)
      File "/Users/sauron/opt/anaconda3/lib/python3.9/site-packages/jupyter_server/services/kernels/websocket.py", line 88, in select_subprotocol
        preferred_protocol = self.connection.kernel_ws_protocol
    AttributeError: 'NoneType' object has no attribute 'kernel_ws_protocol'
[E 2024-10-18 12:49:00.236 ServerApp] {
      "Host": "localhost:8891",
      "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6.1 Safari/605.1.15"
    }
[E 2024-10-18 12:49:00.236 ServerApp] 500 GET /api/kernels/bcf9d8d1-c27d-4c05-a7d3-b81dcf610395/channels?session_id=885fd6fd-7eac-457b-8555-ba9721602f09 (49d96f76b13a4670871e77e5b7b97ba9@::1) 60042.91ms referer=None

I have MacOS BigSur 11.7.10

Any suggestions would be appreciated

Edit your ‘/Users/sauron/opt/anaconda3/lib/python3.9/site-packages/aext_assistant_server/handlers.py’
and in the class ‘NucleusTokenRouteHandler’, change it to be:

class NucleusTokenRouteHandler(APIHandler):
    @tornado.web.authenticated
    async def get(self):
        api_key = _load_api_key()

        #if not api_key:
        #    raise HTTPError(403, reason="missing nucleus_token")

        #expires_at = get_expires_at(api_key)
        expires_at = 0
        self.finish(
            {
                "access_token": api_key,
                "expires_at": expires_at,
            }
        )

comment those lines and adding line ‘expires_at = 0’, that’s all!