在Jupyter笔记本电脑中存储密码 [英] Storing passwords in Jupyter notebooks

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

问题描述

是否可以在笔记本中存储机密/访问机密/密码?我有一个api端点,可以从中提取数据,并且我不想将apiKey公开给所有可以查看笔记本的人.

Is there a way to store secrets/access secrets/passwords in notebooks? I have an api endpoint where I pull data from, and I dont want to expose the apiKey to everyone who can view the notebook.

推荐答案

将凭据存储在JSON或YAML中,并让笔记本解析必要的部分.

Store your credentials in a JSON or YAML, and have your notebook parse the necessary parts.

import json

with open('credentials.json') as f:
    data = json.load(f)
    username = data['username']
    password = data['password']

您应该避免在单元输出中打印秘密,否则您选择的任何技术都会被挫败.

You should avoid printing the secrets in the cell outputs, for otherwise any technique you choose will be foiled.

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

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