0

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:

HappyFace
  • 3,439
  • 2
  • 24
  • 43

1 Answers1

0

This is for JupyterHub, but it might help you.

curl -kvL https://localhost:9443/user/jovyan/api/status -H "Authorization: Token ********************************"

9443 is the SSH tunnelled hub port from the master node of the EMR. The token was generated on the https://localhost:9443/hub/token page.