我有一个正在运行的 jupyterhub 服务,我想以管理员权限与 REST API 交互。
文档建议我可以获得这样的授权令牌,username
管理员用户在哪里:
$ jupyterhub token --config=<path-to-config> <username>
f9ed5a19d62d4285bbebe2ded9028baf
但是,如果我在对 API 的请求中使用此令牌,则会失败:
>>> t1 = 'f9ed5a19d62d4285bbebe2ded9028baf'
>>> requests.get('http://myjupyterhub/hub/api/users', headers={'Authorization': 'token {}'.format(t1)})
>>> <Response [403]>
如果我有用户密码,我可以获得一个令牌,但这在我的场景中很不方便:
>>> r = requests.post('http://myjupyterhub/hub/api/authorizations/token', json={'username': 'myadmin', 'password': myadminpass})
>>> t2 = r.json()['Authentication']
>>> requests.get('http://myjupyterhub/hub/api/users', headers={'Authorization': 'token {}'.format(t2)})
>>> <Response [200]>
我误解了它的jupyterhub token
工作原理吗?