Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error when starting a secure public server for a notebook - IPython 2.2 and tornado 4.0.2 (Debian)

I created a new profile and set it up to be accessible publicaly over https. Such as described on the IPython documentation.

Find bellow the steps I followed

Generated a hashed password:

In [1]: from IPython.lib import passwd
In [2]: passwd()
Enter password:
Verify password:
Out[2]: 'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed'

Created a certificate:

openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mycert.pem -out mycert.pem

and created a new profile.

ipython profile created publicServer

edited the ipython_notebook_config.py file in ~/.ipython/profile_publicServer/

c = get_config()

# Kernel config
c.IPKernelApp.pylab = 'inline'  # if you want plotting support always

# Notebook config
c.NotebookApp.certfile = u'/absolute/path/to/your/certificate/mycert.pem'
c.NotebookApp.ip = '*'
c.NotebookApp.open_browser = False
c.NotebookApp.password = u'sha1:bcd259ccf...[your hashed password here]'
# It is a good idea to put it on a known, fixed port
c.NotebookApp.port = 9999

Then I executed ipython from a terminal to start the notebook using the created profile:

ipython notebook --profile=publicServer

When I try to access it using a browser, from any ip (including localhost)

https://localhost:999

The browser hangs and never loads the page.

On the terminal I get the following error message

ERROR:tornado.application:Exception in callback (<socket._socketobject object at 0x7f76ba974980>, <function null_wrapper at 0x7f76ba918848>)
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/tornado/ioloop.py", line 833, in start
    handler_func(fd_obj, events)
  File "/usr/local/lib/python2.7/dist-packages/tornado/stack_context.py", line 275, in null_wrapper
    return fn(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/tornado/netutil.py", line 201, in accept_handler
    callback(connection, address)
  File "/usr/local/lib/python2.7/dist-packages/tornado/tcpserver.py", line 225, in _handle_connection
    do_handshake_on_connect=False)
  File "/usr/local/lib/python2.7/dist-packages/tornado/netutil.py", line 434, in ssl_wrap_socket
    context = ssl_options_to_context(ssl_options)
  File "/usr/local/lib/python2.7/dist-packages/tornado/netutil.py", line 411, in ssl_options_to_context
    context.load_cert_chain(ssl_options['certfile'], ssl_options.get('keyfile', None))
TypeError: coercing to Unicode: need string or buffer, NoneType found

Could anybody help me fixing this issue?

Cheers

like image 863
mrcl Avatar asked Mar 19 '23 10:03

mrcl


1 Answers

I ran into this problem with a customer. It looks like the Tornado library updated how it does things, and needs to be explicitly told that the certificate/key generated by openssl are the same file.

Here is what you need: in ~/.ipython/profile_{yourprofile}/ipython_notebook_config.py, add the line

c.NotebookApp.keyfile = u'/absolute/path/to/your/certificate/mycert.pem'

Essentially, copy the same line for certfile, and replace keyfile for certfile.

See: Running the Notebook Server, specifically the section "Using SSL/HTTPS".

like image 100
wmorrell Avatar answered Mar 20 '23 22:03

wmorrell