Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JUPYTERHUB_SERVICE_PREFIX problem #997

Closed
whitead opened this issue Feb 22, 2017 · 5 comments
Closed

JUPYTERHUB_SERVICE_PREFIX problem #997

whitead opened this issue Feb 22, 2017 · 5 comments
Labels
Milestone

Comments

@whitead
Copy link
Contributor

whitead commented Feb 22, 2017

How to reproduce the issue

Add the shared notebook as a service managed configuration example to your jupyter configuration with the service name as formgrader-class101. Visit https://hub-url/services/formgrader-class101 and you'll see that custom.css and custom.js give 404s.

What you expected to happen

To not get 404s.

What actually happens

You get 404s

Share what version of JupyterHub you are using

master

Running jupyter troubleshoot from the command line, if possible, and posting
its output would also be helpful.


$PATH:
	/home/awhite38/.local/bin
	/home/awhite38/bin
	/home/awhite38/.local/bin
	/usr/local/sbin
	/usr/local/bin
	/usr/sbin
	/usr/bin
	/sbin
	/bin
	/usr/games
	/usr/local/games
	/snap/bin

sys.path:
	/home/awhite38/.local/bin
	/home/awhite38/dockerspawner
	/usr/lib/python35.zip
	/usr/lib/python3.5
	/usr/lib/python3.5/plat-x86_64-linux-gnu
	/usr/lib/python3.5/lib-dynload
	/home/awhite38/.local/lib/python3.5/site-packages
	/usr/local/lib/python3.5/dist-packages
	/usr/lib/python3/dist-packages

sys.executable:
	/usr/bin/python3

sys.version:
	3.5.2 (default, Nov 17 2016, 17:05:23) 
	[GCC 5.4.0 20160609]

platform.platform():
	Linux-4.4.0-62-generic-x86_64-with-Ubuntu-16.04-xenial

which -a jupyter:
	/home/awhite38/.local/bin/jupyter
	/home/awhite38/.local/bin/jupyter
	/usr/local/bin/jupyter

Workaround

The issue is that the urls for custom.js and custom.css are https://hub-url/services/formgrader-class101custom/custom.css and are missing a forward slash. The following change fixes this:

@@ -178,7 +178,8 @@ class SingleUserNotebookApp(NotebookApp):
     # defaults for some configurables that may come from service env variables:
     @default('base_url')
     def _base_url_default(self):
-        return os.environ.get('JUPYTERHUB_SERVICE_PREFIX') or '/'
+        base_url = os.environ.get('JUPYTERHUB_SERVICE_PREFIX') or ''
+        return base_url + '/'
 
     @default('cookie_name')
     def _cookie_name_default(self):
@willingc
Copy link
Contributor

Thanks @whitead. Do you want to submit a PR or have us make the change?

@willingc willingc added the bug label Feb 24, 2017
@whitead
Copy link
Contributor Author

whitead commented Feb 24, 2017

Yeah, I can submit a PR but I'm pretty sure my workaround is not the correct fix. JUPYTERHUB_SERVICE_PREFIX should probably already have a trailing prefix. It is set at jupyterhub/services/service.py:239 like so:

        if self.url:
            env['JUPYTERHUB_SERVICE_URL'] = self.url
            env['JUPYTERHUB_SERVICE_PREFIX'] = self.server.base_url

where self.server refers to a Server object whose default value for base_url is '/'. So I can try to dig further to see where it is set to something other than a trailing slash. @minrk could probably solve this in 2 minutes though if he can find the time :D.

@whitead
Copy link
Contributor Author

whitead commented Feb 24, 2017

Maybe this line in jupyterhub/apihandlers/service.py:17.

def service_model(service):
    """Produce the model for a service"""
    return {
        'name': service.name,
        'admin': service.admin,
        'url': service.url,
        'prefix': service.server.base_url if service.server else '',
        'command': service.command,
        'pid': service.proc.pid if service.proc else 0,
    }

the else '' should be else '/'?

@minrk
Copy link
Member

minrk commented Feb 26, 2017

@whitead you are right that the SERVICE_PREFIX should indeed always end in a slash. The service_model is unlikely to be the source, because that's only for the REST API when asking where services are running, and else will only be triggered for services that have no web component. This can be doubly fixed:

  1. ensure Service.prefix has a trailing slash by adding + '/' to the end here
  2. single-user server should ensure base_url starts and ends with a slash, by adding a validator (no need for changing the default function):
@validate('base_url')
def _validate_base_url(self, proposal):
    """ensure base_url starts and ends with /"""
    value = proposal.value
    if not value.startswith('/'):
        value = '/' + value
    if not value.endswith('/'):
        value = value + '/'
    return value

Looking forward to your PR!

@minrk minrk added this to the 0.8 milestone Feb 26, 2017
whitead added a commit to whitead/jupyterhub that referenced this issue Feb 27, 2017
@whitead
Copy link
Contributor Author

whitead commented Feb 27, 2017

Thank you for the highly detailed instructions 👍 Your suggestions fix the problem. I've put it into PR #1003.

whitead added a commit to whitead/jupyterhub that referenced this issue Feb 27, 2017
Fixes Issue jupyterhub#997. Also updated Traitlets to 4.3.2 since the change in singleuser.py relies on trait default values being checked through validator, which was added in traitlets 4.3.2.
@whitead whitead closed this as completed Feb 28, 2017
chicocvenancio pushed a commit to chicocvenancio/jupyterhub that referenced this issue May 6, 2018
Fixes Issue jupyterhub#997. Also updated Traitlets to 4.3.2 since the change in singleuser.py relies on trait default values being checked through validator, which was added in traitlets 4.3.2.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants