CORS-error when loading bokeh plot into dockerized jupyter notebook

[Bokeh 2.3.2]
Hi there,

I am encountering a CORS-error when trying to load a bokeh plot into my dockerized jupyter notebook.

Error

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:46487/autoload.js?bokeh-autoload-element=2306&bokeh-absolute-url=http://localhost:46487&resources=none. (Reason: CORS request did not succeed).

The notebook itself is at port 60000 and the notebook_url is also set to that.
Is that a problem that can be fixed inside bokeh or will I have to tweak the docker container?

Best regards

@kaprisonne I am afraid “dockerized jupyter notebook” leaves a lot to the imagination. Quite a bit more detail is needed. Are you connecting remotely? Locally?

Hey @Bryan ,

it’s an ubuntu container and it’s remote. Ports are mapped to local ports through an SSH tunnel (so it shouldn’t really matter if it’s remote).
I reckon it might be because the bokeh server’s ports(46487 in the example) are not explicitly tunneled, yet?

Is there a way to predict what ports are used by the bokeh server or manually specify them? It seems random and I am displaying multiple plots (=multiple bokeh servers=multiple ports used)

I am showing the plot in the notebook like so:

notebook_url = "http://localhost:60000"
show(modify_doc, notebook_url=notebook_url)

Thank you in advance

Any additional keyword args you supply to show will be passed to Server, so you should just be able to pass a port argument to fix the port. However, do be aware of the reason they are randomized by default: if you re-execute the cell with the same fixed port quickly, things are likely to fail, due to the existing port still already being open. (Clearing the output cell triggers cleanup but it takes some time).

Great, thanks!

However, do be aware of the reason they are randomized by default: if you re-execute the cell with the same fixed port quickly, things are likely to fail, due to the existing port still already being open.

Thanks for the heads up. I’m sure I can come up with something to play around that.

I will try it out later and update this thread.

1 Like

Nice,
forwarding the port made everything work.

Thanks!

1 Like