与受密码保护的Jupyter/api交互 [英] Interact with password protected Jupyter /api

查看:134
本文介绍了与受密码保护的Jupyter/api交互的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友正在尝试运行脚本,以检查哪些笔记本使用了最多的内存,但是它们的服务器是密码受保护的.我试图弄清楚如何使用urllib2配置身份验证,因为我不相信用户名,只有密码.

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.

推荐答案

@aiguofer的答案对我不起作用,因为jupyter现在在cookie中使用了"_xsrf".人们为我惊醒:

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)

之后,可以使用s来调用api.

After that s can be used to call the apis.

这篇关于与受密码保护的Jupyter/api交互的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆