Django + Bokeh Server -- good news/bad news

As I promised before, I’m going to share a project template repository to the group that shows Bokeh Server running via Django.
I’m going to have a tutorial that takes you step-by-step to install this on a production server.

If someone else beat me to the punch then kudos . . . I’d love to compare notes.

I should have it posted in the next few days, but for the time being I ran into an issue that I wanted to share and discuss here.

The good news is that I got it working in Bokeh 0.12.9. The bad new is that it doesn’t work in 0.12.10. (using Python 3.5.2 on Ubuntu 16.04 LTS)

I think (but I’m not sure) the session information is not being served properly in version 0.12.10.

I set up these environment variables via the settings.py file in Django:

os.environ[“BOKEH_SECRET_KEY”] = “blahblahblah”

os.environ[“BOKEH_SIGN_SESSIONS”] = “True”

and I run the bokeh server through systemd via a file called bokehserver.service

[Unit]
Description=Bokeh Server
After=network.target

[Service]
Environment="BOKEH_SECRET_KEY=blahblahblah"
User=deployer1
Group=www-data
WorkingDirectory=/home/deployer1/BokehDjango/bokehdash/BokehApps
ExecStart=/home/deployer1/envs/BokehDjango352/bin/bokeh serve sliders.py selection_histogram.py --allow-websocket-origin 45.33.6.39 --address 127.0.0.1 --session-ids external-signed

[Install]
WantedBy=multi-user.target

and then call the session information from the running bokeh server application in the views.py file:

server_script = server_session(None, session_id=session_id.generate_session_id(), url=bokeh_server_url)

And it works perfectly for 0.12.9, but not 0.12.10

server_session returns None with the new version (and therefore the session isn’t recognized/authenticated), and it returns an object in the old version.

I should note that I verified the server is running in both versions – I just can’t get Django to pull in the information.

Am I doing something wrong or unsupported, or did something change (on purpose or accidentally) in the new version?

I’m happy to share more details and source code, but to give an actual working example I think you need to spin up the whole environment since I use nginx as well.

Cheers,

Jonathan

I’m bumping this in case it got overlooked, plus I’m providing a reproducible example.

Problem: server_session doesn’t appear to work under Bokeh 0.12.10 but works under 0.12.9

I tried this in both Python 3.6.2 and 3.5.2

Window 1

Activate Virtual Env:

C:\BokehApps> activate bokehdjango36

Set the secret key:

(bokehdjango26) C:\BokehApps> set BOKEH_SECRET_KEY=kitjOI83DgklnTuUykyHYABBCaV8oItJTZTQqVBav97G

Run Bokeh Server

(bokehdjango26) C:\BokehApps> bokeh serve sliders.py --allow-websocket-origin “*” --session-ids external-signed

Window 2

Activate Virtual Env:

C:> activate bokehdjango36

Start Python

(bokehdjango36) C:>python

Python 3.6.2 |Continuum Analytics, Inc.| (default, Jul 20 2017, 12:30:02) [MSC v.1900 64 bit (AMD64)] on win32

Type “help”, “copyright”, “credits” or “license” for more information.

from bokeh.embed import server_session

from bokeh.util import session_id

bokeh_server_url = “http://localhost:5006/sliders

server_script = server_session(None, session_id=session_id.generate_session_id(), url=bokeh_server_url)

server_script

‘\n<script\n src=“http://localhost:5006/sliders/autoload.js?bokeh-autoload-element=bb392449-4b01-4e91-855d-44f42b408e38&bokeh-app-path=/sliders&bokeh-absolute-url=http://localhost:5006/sliders&bokeh-session-id=PXNM7dY2GneCdJznRZMnJ8WLbohbFB3NYMZZ7j3A8c91”\n id=“bb392449-4b01-4e91-855d-44f42b408e38”\n data-bokeh-model-id=""\n data-bokeh-doc-id=""\n>’

as you can see, server_script returns a value and life is good b/c the rest of my application works fine

but under 0.12.10 everything is the same except for:

server_script = server_session(None, session_id=session_id.generate_session_id(), url=bokeh_server_url)

Traceback (most recent call last):

File “”, line 1, in

File “C:\Python\Anaconda3\envs\bokehdjango36\lib\site-packages\bokeh\util\api.py”, line 190, in wrapper

return obj(*args, **kw)

File “C:\Python\Anaconda3\envs\bokehdjango36\lib\site-packages\bokeh\embed\server.py”, line 188, in server_session

modelid = model._id,

AttributeError: ‘NoneType’ object has no attribute ‘_id’

So, either I’m using this in an unsupported manner (help!!??) or something happened between the two versions. Should I file a bug report?

Thanks,

Jonathan

···

On Friday, November 3, 2017 at 10:41:04 AM UTC-5, Jonathan Bennett wrote:

As I promised before, I’m going to share a project template repository to the group that shows Bokeh Server running via Django.
I’m going to have a tutorial that takes you step-by-step to install this on a production server.

If someone else beat me to the punch then kudos . . . I’d love to compare notes.

I should have it posted in the next few days, but for the time being I ran into an issue that I wanted to share and discuss here.

The good news is that I got it working in Bokeh 0.12.9. The bad new is that it doesn’t work in 0.12.10. (using Python 3.5.2 on Ubuntu 16.04 LTS)

I think (but I’m not sure) the session information is not being served properly in version 0.12.10.

I set up these environment variables via the settings.py file in Django:

os.environ[“BOKEH_SECRET_KEY”] = “blahblahblah”

os.environ[“BOKEH_SIGN_SESSIONS”] = “True”

and I run the bokeh server through systemd via a file called bokehserver.service

[Unit]
Description=Bokeh Server
After=network.target

[Service]
Environment="BOKEH_SECRET_KEY=blahblahblah"
User=deployer1
Group=www-data
WorkingDirectory=/home/deployer1/BokehDjango/bokehdash/BokehApps
ExecStart=/home/deployer1/envs/BokehDjango352/bin/bokeh serve sliders.py selection_histogram.py --allow-websocket-origin 45.33.6.39 --address 127.0.0.1 --session-ids external-signed

[Install]
WantedBy=multi-user.target

and then call the session information from the running bokeh server application in the views.py file:

server_script = server_session(None, session_id=session_id.generate_session_id(), url=bokeh_server_url)

And it works perfectly for 0.12.9, but not 0.12.10

server_session returns None with the new version (and therefore the session isn’t recognized/authenticated), and it returns an object in the old version.

I should note that I verified the server is running in both versions – I just can’t get Django to pull in the information.

Am I doing something wrong or unsupported, or did something change (on purpose or accidentally) in the new version?

I’m happy to share more details and source code, but to give an actual working example I think you need to spin up the whole environment since I use nginx as well.

Cheers,

Jonathan

Hi,

I believe you are seeing:

  https://github.com/bokeh/bokeh/issues/7128

Which was recently fixed in:

  https://github.com/bokeh/bokeh/pull/7133

Thanks,

Bryan

···

On Nov 8, 2017, at 08:35, Jonathan Bennett <[email protected]> wrote:

I'm bumping this in case it got overlooked, plus I'm providing a reproducible example.

Problem: server_session doesn't appear to work under Bokeh 0.12.10 but works under 0.12.9
I tried this in both Python 3.6.2 and 3.5.2

Window 1
Activate Virtual Env:
     C:\BokehApps> activate bokehdjango36
Set the secret key:
     (bokehdjango26) C:\BokehApps> set BOKEH_SECRET_KEY=kitjOI83DgklnTuUykyHYABBCaV8oItJTZTQqVBav97G
Run Bokeh Server
     (bokehdjango26) C:\BokehApps> bokeh serve sliders.py --allow-websocket-origin "*" --session-ids external-signed

Window 2
Activate Virtual Env:
     C:\> activate bokehdjango36
Start Python
     (bokehdjango36) C:\>python
     Python 3.6.2 |Continuum Analytics, Inc.| (default, Jul 20 2017, 12:30:02) [MSC v.1900 64 bit (AMD64)] on win32
     Type “help”, “copyright”, “credits” or “license” for more information.
     >>> from bokeh.embed import server_session
     >>> from bokeh.util import session_id
     >>> bokeh_server_url = “http://localhost:5006/sliders
     >>> server_script = server_session(None, session_id=session_id.generate_session_id(), url=bokeh_server_url)
     >>> server_script
     ‘\n<script\n src=“http://localhost:5006/sliders/autoload.js?bokeh-autoload-element=bb392449-4b01-4e91-855d-44f42b408e38&bokeh-app-path=/sliders&bokeh-absolute-url=http://localhost:5006/sliders&bokeh-session-id=PXNM7dY2GneCdJznRZMnJ8WLbohbFB3NYMZZ7j3A8c91”\n id=“bb392449-4b01-4e91-855d-44f42b408e38”\n data-bokeh-model-id=""\n data-bokeh-doc-id=""\n></script>’

as you can see, server_script returns a value and life is good b/c the rest of my application works fine

but under 0.12.10 everything is the same except for:
     >>> server_script = server_session(None, session_id=session_id.generate_session_id(), url=bokeh_server_url)
     Traceback (most recent call last):
       File "<stdin>", line 1, in <module>
       File "C:\Python\Anaconda3\envs\bokehdjango36\lib\site-packages\bokeh\util\api.py", line 190, in wrapper
         return obj(*args, **kw)
       File "C:\Python\Anaconda3\envs\bokehdjango36\lib\site-packages\bokeh\embed\server.py", line 188, in server_session
         modelid = model._id,
     AttributeError: 'NoneType' object has no attribute '_id'

So, either I'm using this in an unsupported manner (help!!??) or something happened between the two versions. Should I file a bug report?

Thanks,
Jonathan

On Friday, November 3, 2017 at 10:41:04 AM UTC-5, Jonathan Bennett wrote:
As I promised before, I'm going to share a project template repository to the group that shows Bokeh Server running via Django.
I'm going to have a tutorial that takes you step-by-step to install this on a production server.
If someone else beat me to the punch then kudos . . . I'd love to compare notes.

I should have it posted in the next few days, but for the time being I ran into an issue that I wanted to share and discuss here.

The good news is that I got it working in Bokeh 0.12.9. The bad new is that it doesn't work in 0.12.10. (using Python 3.5.2 on Ubuntu 16.04 LTS)

I think (but I'm not sure) the session information is not being served properly in version 0.12.10.

I set up these environment variables via the settings.py file in Django:

os.environ["BOKEH_SECRET_KEY"] = "blahblahblah"
os.environ["BOKEH_SIGN_SESSIONS"] = "True"

and I run the bokeh server through systemd via a file called bokehserver.service

[Unit]
Description=Bokeh Server
After=network.target

[Service]
Environment="BOKEH_SECRET_KEY=blahblahblah"
User=deployer1
Group=www-data
WorkingDirectory=/home/deployer1/BokehDjango/bokehdash/BokehApps
ExecStart=/home/deployer1/envs/BokehDjango352/bin/bokeh serve sliders.py selection_histogram.py --allow-websocket-origin 45.33.6.39 --address 127.0.0.1 --session-ids external-signed

[Install]
WantedBy=multi-user.target

and then call the session information from the running bokeh server application in the views.py file:

server_script = server_session(None, session_id=session_id.generate_session_id(), url=bokeh_server_url)

And it works perfectly for 0.12.9, but not 0.12.10

server_session returns None with the new version (and therefore the session isn't recognized/authenticated), and it returns an object in the old version.
I should note that I verified the server is running in both versions -- I just can't get Django to pull in the information.

Am I doing something wrong or unsupported, or did something change (on purpose or accidentally) in the new version?
I'm happy to share more details and source code, but to give an actual working example I think you need to spin up the whole environment since I use nginx as well.

Cheers,
Jonathan

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/176342df-1e10-4290-928d-4fc4407299d7%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.