I want to access a Jupyter Lab server's API using curl. The server is password protected.
I have tried a number of approaches that did not work.
I have tried using the hash of the password with --header "Authorization: token ${hashed_password}"
.
I have tried this python code:
import requests
import sys
import os
url = sys.argv[1]
password = sys.argv[2]
s = requests.Session()
if not url.endswith('/'):
url += '/'
url_login = f'{url}login/'
url_status = f'{url}api/status/'
resp = s.get(url_login)
xsrf_cookie = resp.cookies['_xsrf']
params={'_xsrf':xsrf_cookie, 'password': password}
print(s.post(url_login, data=params))
print(s.post(url_status, data=params))
I have tried:
local tmp
tmp="$(gmktemp)"
if test -n "$password" ; then
login_response="$(curl -s -X POST -c "$tmp" "${server}login" -d "password=${password}")"
fi
curl -c "$tmp" --silent --request GET "${server}api/status"
What should I do?
Related:
- Interact with password protected Jupyter /api (answers here are outdated and focus on using the API with Python, not curl)