jupyterhub / tmpauthenticator

JupyterHub authenticator that hands out temporary accounts for everyone. For use in tmpnb.org
BSD 3-Clause "New" or "Revised" License
23 stars 18 forks source link

AttributeError: 'coroutine' object has no attribute 'url' #17

Closed andrey-khashchin closed 5 years ago

andrey-khashchin commented 5 years ago

Hi, I managed to complete setup of https://github.com/jupyterhub/jupyterhub-deploy-docker with tmpauthenticator successfully however when I tried to go through the process of fresh install on several other machines, I got an error when I'm trying to access JupyterHub:

[E 2019-03-29 20:06:31.124 JupyterHub web:1788] Uncaught exception GET /hub/tmplogin (172.20.0.3)
    HTTPServerRequest(protocol='http', host='localhost:8000', method='GET', uri='/hub/tmplogin', version='HTTP/1.1', remote_ip='172.20.0.3')
    Traceback (most recent call last):
      File "/opt/conda/lib/python3.6/site-packages/tornado/web.py", line 1699, in _execute
        result = await result
      File "/opt/conda/lib/python3.6/site-packages/tmpauthenticator/__init__.py", line 37, in get
        self.redirect(self.get_argument("next", user.url))
    AttributeError: 'coroutine' object has no attribute 'url'

[D 2019-03-29 20:06:49.820 JupyterHub base:1102] No template for 500
[E 2019-03-29 20:06:49.821 JupyterHub log:166] {
      "Connection": "close",
      "Accept-Encoding": "gzip, deflate",
      "Accept-Language": "en-us",
      "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.1.2 Safari/605.1.15",
      "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
      "Upgrade-Insecure-Requests": "1",
      "Host": "localhost:8000"
    }

My jupyterhub_config.py looks like this:

# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.

# Configuration file for JupyterHub
import os

c = get_config()

# We rely on environment variables to configure JupyterHub so that we
# avoid having to rebuild the JupyterHub container every time we change a
# configuration parameter.

c.JupyterHub.log_level = "INFO"
c.JupyterHub.authenticator_class = 'tmpauthenticator.TmpAuthenticator'

# Spawn single-user servers as Docker containers
c.JupyterHub.spawner_class = 'dockerspawner.DockerSpawner'

# Spawn containers from this image
c.DockerSpawner.container_image = os.environ['DOCKER_NOTEBOOK_IMAGE']

# JupyterHub requires a single-user instance of the Notebook server, so we
# default to using the `start-singleuser.sh` script included in the
# jupyter/docker-stacks *-notebook images as the Docker run command when
# spawning containers.  Optionally, you can override the Docker run command
# using the DOCKER_SPAWN_CMD environment variable.

spawn_cmd = os.environ.get('DOCKER_SPAWN_CMD', "start-singleuser.sh")
c.DockerSpawner.extra_create_kwargs.update({ 'command': spawn_cmd })

# Connect containers to this Docker network
network_name = os.environ['DOCKER_NETWORK_NAME']

c.DockerSpawner.use_internal_ip = True
c.DockerSpawner.network_name = network_name

# Pass the network name as argument to spawned containers
c.DockerSpawner.extra_host_config = { 'network_mode': network_name }

# Explicitly set notebook directory because we'll be mounting a host volume to
# it.  Most jupyter/docker-stacks *-notebook images run the Notebook server as
# user `jovyan`, and set the notebook directory to `/home/jovyan/work`.
# We follow the same convention.
notebook_dir = os.environ.get('DOCKER_NOTEBOOK_DIR') or '/home/jovyan/work'
c.DockerSpawner.notebook_dir = notebook_dir

# Mount the real user's Docker volume on the host to the notebook user's
# notebook directory in the container
c.DockerSpawner.volumes = { 'jupyterhub-user-{username}': notebook_dir }

# volume_driver is no longer a keyword argument to create_container()
# c.DockerSpawner.extra_create_kwargs.update({ 'volume_driver': 'local' })
# Remove containers once they are stopped
c.DockerSpawner.remove_containers = True

# For debugging arguments passed to spawned containers
c.DockerSpawner.debug = True

# User containers will access hub by container name on the Docker network
c.JupyterHub.hub_ip = 'jupyterhub'
c.JupyterHub.hub_port = 8081

c.JupyterHub.ip = 'jupyterhub'
c.JupyterHub.port = 8000

c.JupyterHub.proxy_api_ip = 'jupyterhub'
c.JupyterHub.proxy_api_port = 8001

c.JupyterHub.confirm_no_ssl = True

# Persist hub data on volume mounted inside container
data_dir = os.environ.get('DATA_VOLUME_CONTAINER', '/data')

c.JupyterHub.cookie_secret_file = os.path.join(data_dir,
    'jupyterhub_cookie_secret')

c.JupyterHub.db_url = 'postgresql://postgres:{password}@{host}/{db}'.format(
    host=os.environ['POSTGRES_HOST'],
    password=os.environ['POSTGRES_PASSWORD'],
    db=os.environ['POSTGRES_DB'],
)

# Whitlelist users and admins

c.Authenticator.whitelist = whitelist = {'jupyter','jovyan'}
c.Authenticator.admin_users = admin = {'jupyter'}

c.JupyterHub.admin_access = True
c.LocalAuthenticator.create_system_users = True

c.JupyterHub.proxy_auth_token = 'jupyter'

pwd = os.path.dirname(__file__)
with open(os.path.join(pwd, 'userlist')) as f:
    for line in f:
        if not line:
            continue
        parts = line.split()
        # in case of newline at the end of userlist file
        if len(parts) >= 1:
            name = parts[0]
            whitelist.add(name)
            if len(parts) > 1 and parts[1] == 'admin':
                admin.add(name)
yuvipanda commented 5 years ago

Fixed in #18