I encounter the same problem.
I have already made a service using RequestHandler
with success.
But I need another service which display a template, so I want to use the BaseHandler
which contains the render_template
method.
In this case, I can’t get my service to run.
KeyError: 'hub'
Uncaught exception
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/tornado/http1connection.py", line 276, in _read_message
delegate.finish()
File "/usr/local/lib/python3.10/dist-packages/tornado/routing.py", line 268, in finish
self.delegate.finish()
File "/usr/local/lib/python3.10/dist-packages/tornado/web.py", line 2378, in finish
self.execute()
File "/usr/local/lib/python3.10/dist-packages/tornado/web.py", line 2400, in execute
self.handler = self.handler_class(
File "/usr/local/lib/python3.10/dist-packages/tornado/web.py", line 231, in __init__
self.clear()
File "/usr/local/lib/python3.10/dist-packages/tornado/web.py", line 332, in clear
self.set_default_headers()
File "/usr/local/lib/python3.10/dist-packages/jupyterhub/handlers/base.py", line 229, in set_default_headers
self.set_header('Content-Security-Policy', self.content_security_policy)
File "/usr/local/lib/python3.10/dist-packages/jupyterhub/handlers/base.py", line 204, in content_security_policy
["frame-ancestors 'self'", "report-uri " + self.csp_report_uri]
File "/usr/local/lib/python3.10/dist-packages/jupyterhub/handlers/base.py", line 194, in csp_report_uri
'csp_report_uri', url_path_join(self.hub.base_url, 'security/csp-report')
File "/usr/local/lib/python3.10/dist-packages/jupyterhub/handlers/base.py", line 154, in hub
return self.settings['hub']
KeyError: 'hub'
Here the code:
class MyHandler(BaseHandler):
async def get(self):
html = await self.render_template("custom_template.html", args=[])
self.finish(html)
def main():
app = Application(
[
(os.environ['JUPYTERHUB_SERVICE_PREFIX'], MyHandler),
(r'.*', MyHandler),
],
cookie_secret=os.urandom(32),
)
http_server = HTTPServer(app)
url = urlparse(os.environ['JUPYTERHUB_SERVICE_URL'])
http_server.listen(url.port, url.hostname)
IOLoop.current().start()
if __name__ == '__main__':
main()
@Data_Mastery Did you managed to adapt your code to service ?