不显示密码的电子邮件和密码身份验证

2024-04-26 13:23:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我发现自己需要登录google才能使用远程api,但是它需要电子邮件和密码来验证进程。有没有我可以隐藏他们两个,并要求项目的其他贡献者添加他们自己的(安全)?你知道吗

from google.appengine.ext.remote_api import remote_api_stub
import database
import getpass

email = "gmail@gmail.com" #can't show this line
password = "password" #can't show this line

def auth_func():
  return (email, password)

remote_api_stub.ConfigureRemoteApi(None, '/_ah/remote_api', auth_func,
                               'app.appspot.com')

Tags: importcomauthapiremoteemailshowgoogle
2条回答

我会把它放在另一个文件里(配置.xml例如)而不是承诺。在构建应用程序之前,您可以验证它是否存在。你知道吗

您可以将敏感信息保存在环境变量中,并在运行应用程序之前在应用程序文档中包含设置环境变量的说明。你知道吗

要从Python中检索变量(从here):

import os

email = os.environ.get("GOOGLE_EMAIL")
password = os.environ.get("GOOGLE_PASSWORD")

if email and password:
    # ... process...

如果您使用的是virtualenv(您应该这么做!)您可能还想使用autoenv(或在this问题中提到的其他工具)这样的工具,当您cd进入项目目录时,它可以为单个命令行/控制台会话设置相关的环境变量。你知道吗

您也可以将命令放在shell脚本/批处理文件中,只需确保不提交它。你知道吗

相关问题 更多 >