Redirect to notebook not working

I have following config file for a python lecture to provide some logins and separated notebooks for the users:

# Configuration file for jupyterhub.

c = get_config()  #noqa

c.JupyterHub.extra_log_file = '/home/jupyteruser/jupyter/log/jupyterhub.log'

c.JupyterHub.bind_url = 'http://0.0.0.0:8002'

import os
users_base_path = '/home/jupyteruser/jupyter/users'
def set_user_environment(spawner):
    username = spawner.user.name
    os.environ['PATH'] = f'{users_base_path}/{username}/bin:{os.environ["PATH"]}'
    os.environ['LD_LIBRARY_PATH'] = f'/home/jupyteruser/jupyter/instantclient_19_5'

c.Spawner.pre_spawn_hook = set_user_environment

c.JupyterHub.authenticator_class = 'firstuseauthenticator.FirstUseAuthenticator'

c.Authenticator.whitelist = {'user01', 'user02', 'user03'} 

c.Spawner.notebook_dir = '/home/jupyteruser/jupyter/users/{username}'
c.Spawner.concurrent_spawn_limit = 20

c.Spawner.dummy_passwords = {
    'user01': 'pwdUser01',
    'user02': 'pwdUser02',
    'user03': 'pwdUser03'
}

from jupyterhub.spawner import SimpleLocalProcessSpawner
c.JupyterHub.spawner_class = SimpleLocalProcessSpawner"

All other settings are default.

On login I get the message “A Jupyter Server is running.” but the notebook doesn’t show up. For e.g. user01 I get from the original link myserver:8002 for login a redirect to myserver:8002/user/user01/?redirects=1. but only the message of running server.

Going to http://lin607:8002/hub/home shows up Stop my Server and My Server buttons. Clicking on My Server gives 404 Not Found error. Clicking Stop my Server shuts down the server. So the server is running but cannot be accessed, neither from the same machine nor from a remote machine (what is what I need).

How to repair this?

Just looking at it quickly, you’re missing the f on your f-string for notebook_dir.

Ok, thank you for the hint. I modifyed the code slightly, but finally end at the same point.

New settings:

c = get_config()  #noqa

c.JupyterHub.extra_log_file = '/home/jupyteruser/jupyter/log/jupyterhub.log'

c.JupyterHub.bind_url = 'http://0.0.0.0:8002'

import os
users_base_path = '/home/jupyteruser/jupyter/users'
def set_user_environment(spawner):
    username = spawner.user.name
    spawner.notebook_dir = f'/home/jupyteruser/jupyter/users/{username}'
    userpath = f'{users_base_path}/{username}/bin'
    os.environ['PATH'] = f'{userpath}:{os.environ["PATH"]}'
    os.environ['LD_LIBRARY_PATH'] = f'/home/jupyteruser/jupyter/instantclient_19_5'
    # hint by ChatGPT
    spawner.environment['PATH'] = f'{userpath}:{os.environ["PATH"]}'
    spawner.environment['LD_LIBRARY_PATH'] = f'/home/jupyteruser/jupyter/instantclient_19_5'
    print("USER CONFIG: set_user_environment called ...")
    print("USER PATH:",userpath)


c.JupyterHub.authenticator_class = 'firstuseauthenticator.FirstUseAuthenticator'

c.Authenticator.whitelist = {'user01', 'user02', 'user03', 'user04'}

c.Spawner.pre_spawn_hook = set_user_environment

c.Spawner.concurrent_spawn_limit = 20

c.Spawner.dummy_passwords = {
    'user01': 'pwdUser01',
    'user02': 'pwdUser02',
    'user03': 'pwdUser03',
    'user04': 'pwdUser04'
}

from jupyterhub.spawner import SimpleLocalProcessSpawner
c.JupyterHub.spawner_class = SimpleLocalProcessSpawner

Output on login:

USER CONFIG: set_user_environment called ...
USER PATH: /home/jupyteruser/jupyter/users/user01/bin

Additionally I get this output:

[W 2023-08-25 08:11:43.945 JupyterHub base:1648] Redirect loop detected on /hub/user/user01/?redirects=2

Browser shows: A Jupyter Server is running.

Before it seems that the server tries to go to http://myserver:8002/user/user01/

The address field of the browser shows finally: http://myserver:8002/user/user01/?redirects=3

@EDIT: After correcting the code to set spawner.environment, I result in 500 : Internal Server Error Redirect loop detected.

I have answered in your other post → Spawned user process not visible from other machine - #4 by mahendrapaipuri

Could you share your full logs?

You saved my day. It was not clear to me, that I have to Install a jupyterlab or jupyter notebook, i.e. I thought that comes with jupyterhub.

Now it is working. Thank you.

1 Like