JupyterHub extra_services. 404 Error when trying to access app

I have the following problem: I want to add a custom Tornado Service to my JupyterHub Service, which runs on an OpenShift Cluster inside a Pod.

I found a similar issue here, which could help to solve our problem: How to set up the jupyterhub services?

c.JupyterHub.services = [
    {"name": "aboutservice",
        "command": [sys.executable, "/usr/local/bin/aboutservice.py"],
        "url": "http://127.0.0.1:8888",
    }]

The app is a very simple Tornado Hello World example.

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        html = "<html><body><h1>Hello, world</h1></body></html>"
        self.write(html)


async def main():
    application = tornado.web.Application(
        [
            (r"/", MainHandler),
        ]
    )
    application.listen(8888)
    await asyncio.Event().wait()


if __name__ == "__main__":
    asyncio.run(main())

The ConfixProxy adds the service as so:

13:30:12.005 [ConfigProxy] info: Route added /services/aboutservice -> http://127.0.0.1:8888

However, the URL mapping seems to be wrong.

“Server at http://127.0.0.1:8888/services/aboutservice/ responded with 404”

Shouldn´t the extra service on port 8888 being mapped to http://127.0.0.1:8080/services/aboutservice/ ?

Does anyone know what we are doing wrong? Thank you for any help!

Curling it works fine:

sh-4.4$ curl 127.0.0.1:8888
<html><body><h1>Hello, world</h1></body></html>sh-4.4$ ^C
sh-4.4$

Your service needs to take into account the URL prefix added by JupyterHub. If you try curl http://127.0.0.1:8888/services/aboutservice/ you should see the same error.

Your service can find out the URL prefix from some environment variables set by JupyterHub, see Services — JupyterHub 3.1.1 documentation

1 Like