在IPython笔记本中请求密码 [英] Requesting password in IPython notebook

查看:111
本文介绍了在IPython笔记本中请求密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个IPython笔记本,它使用加密的ssh密钥文件通过SSH访问数据。我不想将密码存储在笔记本中(也不是单独的文件中)。我可以使用输入来从用户提示读取密码,但在这种情况下,密码在屏幕上可见。有没有办法安全地获取密码?

I have an IPython notebook which accesses data via SSH using encrypted ssh key file. I don't want to store the password in the notebook (nor in a separate file). I can use input in order to read the password from user prompt, but in this case the password is visible on the screen. Is there a way to securely obtaining password?

推荐答案

你应该导入 getpass 模块,然后调用 getpass.getpass

import getpass
password = getpass.getpass()

请注意,在旧版本中,输入密码的字段可能不会出现在IPython Notebook中,而是出现在终端/命令提示符窗口中。但是,在最新版本的Jupyter Notebook中,提示符将出现在Notebook本身。

Note that in old versions, the field where you enter the password may not appear in the IPython Notebook, but instead in your terminal/command prompt window. In the latest versions of Jupyter Notebook, however, the prompt will appear in the Notebook itself.

这篇关于在IPython笔记本中请求密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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