Search code examples
authenticationurllib2jupyterjupyter-notebook

Interact with password protected Jupyter /api


A friend is trying to run a script to check which notebooks are using the most memory, but their server is password protected. I'm trying to figure out how to configure authentication using urllib2 since I don't believe there is a username, only a password.


Solution

  • The @aiguofer answer did not work for me because jupyter now uses '_xsrf' in cookie. The follwoing woked for me:

    s = requests.Session()
    url='http://127.0.0.1:8888/login/'
    resp=s.get(url)
    xsrf_cookie = resp.cookies['_xsrf']
    
    params={'_xsrf':xsrf_cookie,'password': password}
    s.post(url, data=params)
    

    After that s can be used to call the apis.