mathworks / jupyter-matlab-proxy

MATLAB Integration for Jupyter enables you to run MATLAB code in Jupyter Notebooks and other Jupyter environments. You can also open MATLAB in a browser directly from your Jupyter environment to use more MATLAB features.
Other
284 stars 36 forks source link

Proxy does not work with latest matlab? #29

Closed xhejtman closed 1 year ago

xhejtman commented 1 year ago

I tried matlab 2023a with the proxy and I am getting the following error:

Traceback (most recent call last):
  File "/opt/conda/bin/matlab-proxy-app", line 8, in <module>
    sys.exit(main())
  File "/opt/conda/lib/python3.10/site-packages/matlab_proxy/app.py", line 685, in main
    app = create_app(config_name=desired_configuration_name)
  File "/opt/conda/lib/python3.10/site-packages/matlab_proxy/app.py", line 671, in create_app
    app, EncryptedCookieStorage(f, cookie_name="matlab-proxy-session")
  File "/opt/conda/lib/python3.10/site-packages/aiohttp_session/cookie_storage.py", line 28, in __init__
    self._fernet = fernet.Fernet(secret_key)
  File "/opt/conda/lib/python3.10/site-packages/cryptography/fernet.py", line 33, in __init__
    key = base64.urlsafe_b64decode(key)
  File "/opt/conda/lib/python3.10/base64.py", line 131, in urlsafe_b64decode
    s = _bytes_from_decode_data(s)
  File "/opt/conda/lib/python3.10/base64.py", line 45, in _bytes_from_decode_data
    raise TypeError("argument should be a bytes-like object or ASCII "
TypeError: argument should be a bytes-like object or ASCII string, not 'Fernet'
prabhakk-mw commented 1 year ago

Hi @xhejtman Yes, it does work. I have it running on my end.

The issue seems to be stemming from the use of cookie storage, could you please close all browser tabs running matlab-proxy and attempt to connect to the URL from an incognito tab ? Does this work?

If you are still facing issues, please try the following:

To ensure that there aren't any setup issues, we could try to install it in a clean environment:

conda create -n myenv python=3.10 jupyterlab -y
conda activate myenv
python3 -m pip install jupyter-matlab-proxy
jupyter lab

If the issue still persists retry after executing the following command:

rm -rf ~/.matlab
xhejtman commented 1 year ago

It is run from jupyterhub as an image in kubernetes, exact the same works with versioin 2022b.

It does not work from anonymous window.

this is how I extend FROM mathworks/matlab-deep-learning:r2023a

ARG CONDA_MIRROR=https://github.com/conda-forge/miniforge/releases/latest/download

RUN set -x && \
    # Miniforge installer
    miniforge_arch=$(uname -m) && \
    miniforge_installer="Mambaforge-Linux-${miniforge_arch}.sh" && \
    wget --quiet "${CONDA_MIRROR}/${miniforge_installer}" && \
    /bin/bash "${miniforge_installer}" -f -b -p "${CONDA_DIR}" && \
    rm "${miniforge_installer}" && \
    conda config --system --set auto_update_conda false && \
    conda config --system --set show_channel_urls true && \
    conda install --quiet --yes nb_conda_kernels && \
    conda clean --all -f -y && mamba clean --all -f -y && \
    rm -rf "/home/${NB_USER}/.cache/" && conda init

RUN mamba install --yes ipywidgets notebook jupyterhub jupyterlab jupyter-server-proxy && mamba clean --all -f -y && npm cache clean --force && \
    jupyter notebook --generate-config && \
    jupyter lab clean && \
    rm -rf "/home/${NB_USER}/.cache/"
prabhakk-mw commented 1 year ago

Thank you, Would you please provide the full Dockerfile, so that we could reproduce and investigate at our end?

xhejtman commented 1 year ago

We run it via jupyterhub 3.0.0 from zero to jupyterhub instance.

xhejtman commented 1 year ago

matlab-docker.zip fixed dockerfile

xhejtman commented 1 year ago

Hello, anything new here?

prabhakk-mw commented 1 year ago

Although, I dont quite understand the intent of the attached Dockerfile. I was able to build and run it as follows:

docker build -t jmp-issues:29 .

docker run --init -it --rm -p 8888:8888 --entrypoint /bin/bash jmp-issues:29 

$matlab-proxy-app

This did indeed reproduce the failure that you have reported. The error messages point to the function aiohttp_session_setup not accepting Fernet objects.

Further inspection shows that the version of aiohttp-session inside your image is old and does not accept our usage of it:

(base) jovyan@f55175ef246b:~$ python3 -m pip freeze | grep aiohttp
aiohttp @ file:///home/conda/feedstock_root/build_artifacts/aiohttp_1636085263707/work
aiohttp-session==2.9.0

Comparing this against mathworks/matlab-deep-learning:r2023a :

matlab@0294fb367c33:~/Documents/MATLAB$ python3 -m pip freeze |grep  aiohttp
aiohttp==3.8.4
aiohttp-session==2.12.0

I was able to successfully run matlab-proxy-app in your container by upgrading aiohttp-session using

python3 -m pip install --upgrade aiohttp-session

Hope this information unblocks you!