Setting kernel values through request handlers

58 views
Skip to first unread message

Claude Vervoort

unread,
Oct 21, 2018, 10:22:29 AM10/21/18
to Project Jupyter
Hello,

Still new at notebooks and in particular extensions, so i'm not sure what I am after is trivial or not the right way to look at it:

So I want to add an end point to the notebook server that will receive a POST and make the parameters it receives available in the notebook as variables; the notebook would display an IFrame sending a request to an external server, which responds by a form POST to that end point, which would display a success page and ideally make those form post parameters available in the notebook so they can be used in subsequent cells.

So I looked at the various way to extend the notebook, and the custom request handler offers a very simple way to expose a new endpoint. However, I'm not sure how it can process the data it receives and add it to the Kernel so it can be accessed directly within the notebook. I've browsed through many examples of custom request handlers (thanks Github code search!) but did not see any example that seems to do something similar.

I've also looked at widgets, ipython extensions, but I do not see a clear way yet.

Any pointer appreciated,

Thanks!

Claude

Roland Weber

unread,
Oct 22, 2018, 4:35:28 AM10/22/18
to Project Jupyter
Hello Claude,

the notebook server and the kernel where your code cells execute are two different processes. The notebook server cannot directly update the variables in your kernel.

You could translate the variable definitions received in your POST request to code, and send that code for execution to the kernel. Or you could define a custom message that the notebook server sends to the kernel, and install some handler code in the kernel that interprets these messages. The second approach has the advantage that you don't need language-specific logic in the notebook server.

Either way, allowing an external server to send POST requests that change the state of kernel processes sounds like an attack vector. Please be very careful to properly authenticate these requests.

hope this helps,
  Roland

Claude Vervoort

unread,
Oct 22, 2018, 9:44:20 AM10/22/18
to jup...@googlegroups.com
Thanks Roland for the very clear explanation! I'll look at the custom message and if I read you correctly a matching IPython extension to consume it. For the auth, to begin with I was going to check on the logged_in status on the IPythonHandler, or I think I saw a tornado decorator. Anyway still experimenting at this point.

Claude


--
You received this message because you are subscribed to the Google Groups "Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jupyter+u...@googlegroups.com.
To post to this group, send email to jup...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jupyter/d779575f-bd24-4e14-a235-01a8606d2ce6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Roland Weber

unread,
Oct 23, 2018, 2:15:46 AM10/23/18
to Project Jupyter
Hello Claude,


For the auth, to begin with I was going to check on the logged_in status on the IPythonHandler

The external server will not be logged in. Only the client browser is. You'll need to pass some authentication information from the client browser to the external server, so that the external server can prove to Jupyter that its request is on behalf of that client.

Happy hacking :-)
  Roland

Claude Vervoort

unread,
Oct 23, 2018, 11:23:48 AM10/23/18
to jup...@googlegroups.com
Since it is a form post from the IFrame in the notebook, it should pick up the session cookie. Anyway i'll see how it goes, again thx for the help!

Claude

--
You received this message because you are subscribed to the Google Groups "Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jupyter+u...@googlegroups.com.
To post to this group, send email to jup...@googlegroups.com.

Aaron Watters

unread,
Nov 18, 2018, 9:57:58 AM11/18/18
to Project Jupyter
What is the top level "user story"?  IE, what problem are you trying to solve?
 There may be an alternative approach to the detailed method you propose.

my 2p.  -- Aaron Watters

Claude Vervoort

unread,
Nov 18, 2018, 10:29:33 AM11/18/18
to jup...@googlegroups.com
Oh yeah sure... I got it to work but always curious to hear of other patterns since i'm all still new to Jupyter and I use it in a non typical way: i'm building a self-taught course around a new version of a technical specification for e-learning (LTI). This involves flow from the learning management system LMS and the learning app. One of those flows involve sending a POST load to the tool. That will be simulated in an iframe in the notebook. I could just show the result in the iframe and let the user copy/paste the data in a cell for processing. However I'm going to have this post to this handler which will populate the data directly in the kernel to make the process easier.

IFRAME -> fake LMS -> POST hanlder -> set values in kernel and display

I got it to work, I hear there is some security soft point about having the handler setting up some variables in the kernel but in the context, those seems OK for now,

Claude

--
You received this message because you are subscribed to the Google Groups "Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jupyter+u...@googlegroups.com.
To post to this group, send email to jup...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages