我创建了一个新的个人资料,并将其设置为可通过https进行公开访问。如IPython文档中所述。
生成哈希密码:
In [1]: from IPython.lib import passwd
In [2]: passwd()
Enter password:
Verify password:
Out[2]: 'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed'
创建证书:
openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mycert.pem -out mycert.pem
并创建了一个新的个人资料。
ipython profile created publicServer
在〜/ .ipython / profile_publicServer /
中编辑了ipython_notebook_config.py文件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
然后我从终端执行ipython以使用创建的配置文件启动笔记本:
ipython notebook --profile=publicServer
当我尝试使用浏览器从任何ip(包括localhost)
访问它时https://localhost:999
浏览器挂起并且从不加载页面。
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
有人可以帮我解决这个问题吗?
干杯
答案 0 :(得分:7)
我遇到了客户这个问题。看起来Tornado库更新了它的工作方式,需要明确告知openssl生成的证书/密钥是同一个文件。
以下是您的需求:在〜/ .ipython / profile_ {yourprofile} /ipython_notebook_config.py中,添加行
c.NotebookApp.keyfile = u'/absolute/path/to/your/certificate/mycert.pem'
基本上,复制certfile的同一行,并替换certfile的密钥文件。
请参阅:Running the Notebook Server,特别是&#34;使用SSL / HTTPS&#34;。