How to use nbviewer as managed service in jupyterhub?

I try to add the code into the config , but not work and I don’t know how to access , where is the /services/nbviewer on local machine path?
Code below:

c.JupyterHub.services = [
{
‘name’: ‘nbviewer’,
‘url’:‘http://127.0.0.1:9000’,
‘command’: [‘python’, ‘-m’, ‘nbviewer’],
}`
And warnning:
[W 2021-11-18 02:33:23.845 JupyterHub app:2098] Cannot connect to managed service public at http://127.0.0.1:9000

I am confused about wher to store the .ipynb files which I want to display?

GitHub - jupyter/nbviewer: nbconvert as a web service: Render Jupyter Notebooks as static web pages says nbviewer runs on port 8080, not 9000. You’ll either have to configure nbviewer to run on a different port, or change the url in your service definition.

thanks, it work now,but get ner problems , the page below:


and the warning is like:

[I 2021-11-25 09:24:51.654 JupyterHub log:189] 200 GET /hub/api/authorizations/cookie/jupyterhub-services/[secret] (nbviewer@10.0.19.34) 31.98ms
swarmhub_jupyter_cds.1.o7e8vjeiuqdw@c5 | [E 2021-11-25 09:24:51.882 tornado.general web:2990] Could not open static file ‘’
swarmhub_jupyter_cds.1.o7e8vjeiuqdw@c5 | [E 2021-11-25 09:24:51.886 NBViewer web:1219] Uncaught exception in write_error
swarmhub_jupyter_cds.1.o7e8vjeiuqdw@c5 | Traceback (most recent call last):
swarmhub_jupyter_cds.1.o7e8vjeiuqdw@c5 | File “/usr/local/lib/python3.8/dist-packages/tornado/web.py”, line 1704, in _execute
swarmhub_jupyter_cds.1.o7e8vjeiuqdw@c5 | result = await result
swarmhub_jupyter_cds.1.o7e8vjeiuqdw@c5 | File “/usr/local/lib/python3.8/dist-packages/tornado/web.py”, line 2576, in get
swarmhub_jupyter_cds.1.o7e8vjeiuqdw@c5 | self.absolute_path = self.validate_absolute_path(self.root, absolute_path)
swarmhub_jupyter_cds.1.o7e8vjeiuqdw@c5 | File “/usr/local/lib/python3.8/dist-packages/jupyter_server/base/handlers.py”, line 860, in validate_absolute_path
swarmhub_jupyter_cds.1.o7e8vjeiuqdw@c5 | raise web.HTTPError(404)
swarmhub_jupyter_cds.1.o7e8vjeiuqdw@c5 | tornado.web.HTTPError: HTTP 404: Not Found
swarmhub_jupyter_cds.1.o7e8vjeiuqdw@c5 |
swarmhub_jupyter_cds.1.o7e8vjeiuqdw@c5 | During handling of the above exception, another exception occurred:
swarmhub_jupyter_cds.1.o7e8vjeiuqdw@c5 |
swarmhub_jupyter_cds.1.o7e8vjeiuqdw@c5 | Traceback (most recent call last):
swarmhub_jupyter_cds.1.o7e8vjeiuqdw@c5 | File “/usr/local/lib/python3.8/dist-packages/tornado/web.py”, line 1217, in send_error
swarmhub_jupyter_cds.1.o7e8vjeiuqdw@c5 | self.write_error(status_code, **kwargs)
swarmhub_jupyter_cds.1.o7e8vjeiuqdw@c5 | File “/usr/local/lib/python3.8/dist-packages/jupyter_server/base/handlers.py”, line 590, in write_error
swarmhub_jupyter_cds.1.o7e8vjeiuqdw@c5 | html = self.render_template("%s.html" % status_code, **ns)
swarmhub_jupyter_cds.1.o7e8vjeiuqdw@c5 | File “/usr/local/lib/python3.8/dist-packages/jupyter_server/base/handlers.py”, line 521, in render_template
swarmhub_jupyter_cds.1.o7e8vjeiuqdw@c5 | return template.render(**ns)
swarmhub_jupyter_cds.1.o7e8vjeiuqdw@c5 | File “/usr/local/lib/python3.8/dist-packages/jinja2/environment.py”, line 1304, in render
swarmhub_jupyter_cds.1.o7e8vjeiuqdw@c5 | self.environment.handle_exception()
swarmhub_jupyter_cds.1.o7e8vjeiuqdw@c5 | File “/usr/local/lib/python3.8/dist-packages/jinja2/environment.py”, line 925, in handle_exception
swarmhub_jupyter_cds.1.o7e8vjeiuqdw@c5 | raise rewrite_traceback_stack(source=source)
swarmhub_jupyter_cds.1.o7e8vjeiuqdw@c5 | File “/usr/local/lib/python3.8/dist-packages/nbviewer/templates/404.html”, line 1, in top-level template code
swarmhub_jupyter_cds.1.o7e8vjeiuqdw@c5 | {% extends “error.html” %}
swarmhub_jupyter_cds.1.o7e8vjeiuqdw@c5 | File “/usr/local/lib/python3.8/dist-packages/nbviewer/templates/error.html”, line 1, in top-level template code
swarmhub_jupyter_cds.1.o7e8vjeiuqdw@c5 | {% extends “layout.html” %}
swarmhub_jupyter_cds.1.o7e8vjeiuqdw@c5 | File “/usr/local/lib/python3.8/dist-packages/nbviewer/templates/layout.html”, line 89, in top-level template code
swarmhub_jupyter_cds.1.o7e8vjeiuqdw@c5 |
swarmhub_jupyter_cds.1.o7e8vjeiuqdw@c5 | File “/usr/local/lib/python3.8/dist-packages/jinja2/utils.py”, line 84, in from_obj
swarmhub_jupyter_cds.1.o7e8vjeiuqdw@c5 | if hasattr(obj, “jinja_pass_arg”):
swarmhub_jupyter_cds.1.o7e8vjeiuqdw@c5 | jinja2.exceptions.UndefinedError: ‘from_base’ is undefined
swarmhub_jupyter_cds.1.o7e8vjeiuqdw@c5 | [W 2021-11-25 09:24:51.888 NBViewer log:57] 404 GET /services/nbviewer/static/build/styles.css (10.0.0.2) 27.48ms referer=“
http://127.0.0.1:16667/services/nbviewer/” user-agent=“Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36”
swarmhub_jupyter_cds.1.o7e8vjeiuqdw@c5 | [E 2021-11-25 09:24:51.892 NBViewer web:1219] Uncaught exception in write_error
swarmhub_jupyter_cds.1.o7e8vjeiuqdw@c5 | Traceback (most recent call last):
swarmhub_jupyter_cds.1.o7e8vjeiuqdw@c5 | File “/usr/local/lib/python3.8/dist-packages/tornado/web.py”, line 1704, in _execute
swarmhub_jupyter_cds.1.o7e8vjeiuqdw@c5 | result = await result
swarmhub_jupyter_cds.1.o7e8vjeiuqdw@c5 | File “/usr/local/lib/python3.8/dist-packages/tornado/web.py”, line 2576, in get
swarmhub_jupyter_cds.1.o7e8vjeiuqdw@c5 | self.absolute_path = self.validate_absolute_path(self.root, absolute_path)
swarmhub_jupyter_cds.1.o7e8vjeiuqdw@c5 | File “/usr/local/lib/python3.8/dist-packages/jupyter_server/base/handlers.py”, line 860, in validate_absolute_path
swarmhub_jupyter_cds.1.o7e8vjeiuqdw@c5 | raise web.HTTPError(404)
swarmhub_jupyter_cds.1.o7e8vjeiuqdw@c5 | tornado.web.HTTPError: HTTP 404: Not Found

I’ve checked the source code and it looks like your original configuration ‘url’:‘http://127.0.0.1:9000’, should’ve worked- nbviewer should get this information from the JUPYTERHUB_SERVICE_URL environment variable:

The fact that it didn’t work, and that you’re seeing issues with static files when running on the default port 8080, suggests that nbviewer isn’t reading this variable.

If you switch back to port 9000 and turn on debug JupyterHub logging you should see the startup logs from nbviewer. Can you show us those logs, or if it’s easier show us the full JupyterHub logs.

1 Like