【发布时间】:2018-04-17 11:36:14
【问题描述】:
我通过 Heroku 设置了一些环境变量来访问 GrapheneDB 实例。当我使用 Heroku CLI 命令heroku config 时,所有环境变量都按预期返回。
例如,"heroku config" 返回:
GRAPHENEDB_BOLT_PASSWORD: some_password
GRAPHENEDB_BOLT_URL: bolt://hobby-someletters.dbs.graphenedb.com:24786
GRAPHENEDB_BOLT_USER: appnumbers
GRAPHENEDB_URL: http://appnumbers:some_password@hobby-someletters.dbs.graphenedb.com:24789
NEO4J_REST_URL: GRAPHENEDB_URL
但是,当我尝试使用os.environ.get() 方法访问这些环境变量时,所有三个打印语句都返回None,而不是heroku config 返回的所需输出。这向我表明 Python 环境无权访问 Heroku 环境变量。如何让 python 访问这些?
import os
from py2neo import Graph
graphenedb_url = os.environ.get('GRAPHENEDB_BOLT_URL')
graphenedb_user = os.environ.get("GRAPHENEDB_BOLT_USER")
graphenedb_pass = os.environ.get("GRAPHENEDB_BOLT_PASSWORD")
print(graphenedb_url)
print(graphenedb_user)
print(graphenedb_pass)
我尝试过使用Acess Heroku variables from Flask 的解决方案
但是当我执行命令时:
heroku config:pull --overwrite
CLI 返回
config:pull is not a heroku command.
【问题讨论】:
标签: python heroku environment-variables