HTTP 500 error in Docker Jupyterhub when requesting user tokens

Hoi there,

I’m trying to create tokens (non API) for a number of auto-created users. Here’s what I’m doing:

  1. Create Docker image of a Jupyterhub with a custom configure file that has an admin user and API token (works)
  2. Start the Docker image as a container (works)
  3. Test the REST API with the admin token to see if I have access (works)
  4. Use the REST API with the admin token to create users (works)
  5. Use the REST API to create tokens for each created user using the same admin user and token (fails)

The POST url I’m using is (fictitious username):


With JSON body taken directly from the API documentation:

   "expires_in": 0,
   "note":"Automatically generated auth token",

In the console where I run the custom container I see the following.

[I 2023-04-07 17:34:10.708 JupyterHub users:421] Service admin requested API token for cstuart
[E 2023-04-07 17:34:10.709 JupyterHub web:1798] Uncaught exception POST /hub/api/users/cstuart/tokens (::ffff:
    HTTPServerRequest(protocol='http', host='localhost:10000', method='POST', uri='/hub/api/users/cstuart/tokens', version='HTTP/1.1', remote_ip='::ffff:')
    Traceback (most recent call last):
      File "/usr/local/lib/python3.10/dist-packages/tornado/", line 1713, in _execute
        result = await result
      File "/usr/local/lib/python3.10/dist-packages/jupyterhub/apihandlers/", line 431, in post
        token_model = self.token_model(orm.APIToken.find(self.db, api_token))
      File "/usr/local/lib/python3.10/dist-packages/jupyterhub/apihandlers/", line 233, in token_model
        if token.user:
    AttributeError: 'NoneType' object has no attribute 'user'
[E 2023-04-07 17:34:10.709 JupyterHub log:178] {
      "X-Forwarded-Host": "localhost:10000",
      "X-Forwarded-Proto": "http",
      "X-Forwarded-Port": "10000",
      "X-Forwarded-For": "::ffff:",
      "Content-Length": "109",
      "Connection": "close",
      "Accept-Encoding": "gzip, deflate, br",
      "Host": "localhost:10000",
      "Postman-Token": "1f0a63d6-c1bf-4b91-88e0-e7c862620495",
      "Accept": "*/*",
      "User-Agent": "PostmanRuntime/7.29.2",
      "Content-Type": "application/json",
      "Authorization": "token [secret]"
[E 2023-04-07 17:34:10.709 JupyterHub log:186] 500 POST /hub/api/users/cstuart/tokens (admin@::ffff: 8.44ms