ansible / ansible-jupyter-kernel

Jupyter Notebook Kernel for running Ansible Tasks and Playbooks
Other
533 stars 61 forks source link

Jupyterhub/lab ; Python 3.6 : using #vault_password throws type error #81

Open sconburg opened 5 years ago

sconburg commented 5 years ago

Describe the bug

In the case of running ansible_kernel on a python3.6 install of jupyterhub/lab; when using the #vault_password keyword the following error is raised.

TypeError                                 Traceback (most recent call last)
<ipython-input-1-2c7e8874a5d5> in <module>
      1 import ansible_kernel.widgets
      2 style = {'description_width': 'initial'}
----> 3 ansible_kernel.widgets.VaultPassword(description='Vault Password:', style=style)
TypeError: a bytes-like object is required, not 'str'

To Reproduce Dockerfile below:

FROM centos:latest

RUN curl -sL https://rpm.nodesource.com/setup_10.x | bash - && \
    yum -y install https://centos7.iuscommunity.org/ius-release.rpm && \
    yum -y install epel-release && \
    yum -y install python36u python36u-libs python36u-devel python36u-pip nodejs gcc && \
    pip3.6 --cert /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem install --upgrade pip

RUN pip3.6 install jupyterhub jupyterlab notebook && \
    pip3.6 install ansible ansible-kernel ipython && \
    pip3.6 install ipywidgets && \
    npm install -g configurable-http-proxy

RUN jupyter labextension install @jupyterlab/hub-extension && \
    jupyter labextension install @jupyter-widgets/jupyterlab-manager &&\
    jupyter nbextension enable --py widgetsnbextension --sys-prefix && \
    python3.6 -m ansible_kernel.install

RUN useradd -ms /bin/bash -p "$(openssl passwd -1 test)" test 

RUN echo $'import os \n\
c = get_config() \n\
c.Spawner.cmd = [\'jupyter-labhub\'] \n' > jupyterhub_config.py

CMD jupyterhub -f jupyterhub_config.py

Spin up container with:

docker build --rm -f "bug_reproduce\Dockerfile" -t bug_reproduce:latest bug_reproduce
docker run -p 8000:8000 -d -it --name jupyter_bug bug_reproduce

Expected behavior Interactive widget should appear as per second screenshot

Screenshots This is the error which is seen within the ansible_kernel.

image

This is what should be seen (this example is run directly from python kernel).

image

Desktop (please complete the following information):

Additional Information Not sure if it is relevant but running the python snippet shown above in the second screenshot throws the same error when run with #python keyword on ansible_kernel.

benthomasson commented 5 years ago

Thanks @sconburg for submitting this issue. I'll take a look at it under Jupyter lab. I'll work on Jupyter Lab integration for the next release.

philipsd6 commented 3 years ago

FWIW, this isn't a JupyterLab problem -- this issue applies to the basic Jupyter Notebook as well.

almereyda commented 1 year ago

@jldowns has a fix in https://github.com/jldowns/ansible-jupyter-kernel/commit/a89ab751e71cba5b2714683536dfac18d8addd52

Would this be useful and non-invasive enough to take in here?