Jupyterhub REST API returns 403 for binderhub


I have set up binderhub at our University, and I can’t get jupyterhub REST API to work.
I can launch a server without any issues following the guide on binderhub Github: binderhub/binder-api.py at 73c73394b64705c5391fadda65fe9bf36c4b6e38 · jupyterhub/binderhub · GitHub

This however does not work:

import requests


api_url = f"{hub_url}/hub/api/info?token={token}"
r = requests.get(api_url)

I get error message:" 403 Client Error: Forbidden for url: https://hub.binder.bla.bla/hub/api/users"
The first thing I tried was disabling authentication for binderhub, and remove the token part above, but it still gave the same error message.

I suspect I’ve misunderstood how the rest api works.

I got this to work!

?token={token} does not work in this case. I had to do the following instead:

api_url = f"{hub_url}/hub/api/users"
r = requests.get(api_url,
        'Authorization': f'token {token}',
1 Like