将机密(密码)存储在单独的文件中 [英] Storing the secrets (passwords) in a separate file

查看:145
本文介绍了将机密(密码)存储在单独的文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为Python脚本存储应用程序秘密(密码,访问令牌)的最简单方法是什么?我以为它像Ruby中一样是*.yml文件,但令人惊讶的是我发现事实并非如此.那是什么呢?最简单的解决方案是什么?

What's the simplest way to store the application secrets (passwords, access tokens) for a Python script? I thought it'd be a *.yml file like in Ruby but surprisingly I found that it wasn't the case. So what is it then? What are the most simplest solutions?

我想将它们放置在单独的文件中,因为那样我将不能将其推送到github存储库中.

I want to put them in a separate file because that way I'll be able not to push that file to a github repository.

推荐答案

我认为将凭据存储在另一个* py文件中是您最安全的选择.然后将其导入.示例看起来像这样

I think storing credentials inside another *py file is your safest bet. Then just import it. Example would look like this

config.py

config.py

username = "xy"
password = "abcd"

main.py

import config
login(config.username, config.password)

这篇关于将机密(密码)存储在单独的文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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