Ask Your Question
0

does sage server API work in 5.10?

asked 2013-08-25 17:26:41 +0200

ADuC812 gravatar image

I am trying to run a simple notebook server to use API described here and here

I run the following code in sage command line:

sage:version()

'Sage Version 5.10, Release Date: 2013-06-17'

sage: from sagenb.notebook.notebook_object import test_notebook                                     
sage: passwd = str(randint(1,1<<128))                                                               
sage: nb = test_notebook(passwd, secure=False, interface='localhost', port=Integer(9000), verbose=True, directory=None)

Instead of running server, I get the following:


AttributeError                            Traceback (most recent call last)
<ipython-input-8-6fc45872bdcd> in <module>()
----> 1 nb = test_notebook(passwd, secure=False, interface='localhost', port=Integer(9000), verbose=True,directory=None)

/opt/sage/devel/sagenb/sagenb/notebook/notebook_object.pyc in test_notebook(admin_passwd, secure, directory, port, interface, verbose)
    266 
    267     nb = _notebook.load_notebook(directory)
--> 268     nb.set_accounts(True)
    269     nb.add_user('admin', admin_passwd, '')
    270     nb.set_accounts(False)
AttributeError: 'Notebook' object has no attribute 'set_accounts'

I have also tried to connect to a "normal" sage server created by notebook() via 'simple' URL:

http://localhost:8080/simple/login?username=admin&password=%s

which returns error 404

Does the sage server API work in sage 5.10? Is there a workaround how to create such server? Is there any other way to execute some sage code remotely?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2013-08-27 17:05:03 +0200

ADuC812 gravatar image

Looks that I can set up a twisted conch ssh server as described here to run it in sage, and execute everything that comes through ssh channel. Testing this approach I had to install only pyasn1 into sage, which is a conch dependency, otherwise the example server from the link above works out-of-the-box.

Later I will maybe post a complete solution, as soon as I get there...

edit flag offensive delete link more
1

answered 2013-08-26 16:18:29 +0200

ppurka gravatar image

This is very weird. That particular file sagenb/notebook/notebook_object.py never gets doctested which is why this failure was never detected. The first documentation you linked to is very old - the notebook code has changed a lot in the meanwhile, with a move to flask.

One fix for the error you are getting is the following diff, applied to the sagenb repository:

diff --git a/sagenb/notebook/notebook_object.py b/sagenb/notebook/notebook_object.py
index 431b187..4574d3f 100644
--- a/sagenb/notebook/notebook_object.py
+++ b/sagenb/notebook/notebook_object.py
@@ -251,6 +251,7 @@ def test_notebook(admin_passwd, secure=False, directory=None, port=8050,
         sage: from sagenb.notebook.notebook_object import test_notebook
         sage: passwd = str(randint(1,1<<128))
         sage: nb = test_notebook(passwd, interface='localhost', port=8060)
+        Executing twistd ...
         sage: import urllib
         sage: h = urllib.urlopen('http://localhost:8060')
         sage: homepage = h.read()
@@ -270,9 +271,7 @@ def test_notebook(admin_passwd, secure=False, directory=None, port=8050,
         os.makedirs(directory)

     nb = _notebook.load_notebook(directory)
-    nb.set_accounts(True)
-    nb.add_user('admin', admin_passwd, '')
-    nb.set_accounts(False)
+    nb.create_default_users(admin_passwd)
     nb.save()

     p = notebook(directory=directory, accounts=True, secure=secure, port=port,

After applying this patch, the file notebook_object.py passes all doctests. But it doesn't seem possible to run the following command anymore:

sage: login_page = get_url('http://localhost:%s/simple/login?username=admin&password=%s' % (port, passwd))

I don't see the /simple path in the current notebook code. So, you will have to find some other way of logging in.

The better option for you might be to use the sage cell server. See this page for examples.

edit flag offensive delete link more

Comments

I have noticed that the essential documentation page is old, therefore was asking how much relevant it is. Seems that completely irrelevant. The sage cell server might look fine, but I am a complete noob in modern web technologies that are used in this server. I can just hope that it does not require to write half of a browser to get something written onto that cell and evaluated. Oh, and I need to get the result as well ... Can anyone tell me what to start with (or maybe even some examples???)

ADuC812 gravatar imageADuC812 ( 2013-08-26 16:44:43 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2013-08-25 17:26:41 +0200

Seen: 305 times

Last updated: Aug 27 '13