I'm new to python and I cannot seem to figure out why I cannot get the os.getenv()
function to work. It keeps returning None
which is the default value if something is not there. Here is my code:
import os
import datetime
import plaid
from flask import Flask
from flask import render_template
from flask import request
from flask import jsonify
app = Flask(__name__)
PLAID_CLIENT_ID='entercharhere'
PLAID_ENV='sandbox'
#edit here
os.environ['PLAID_CLIENT_ID']='entercharhere'
os.environ['PLAID_ENV']='sandbox'
print(PLAID_CLIENT_ID)
# Fill in your Plaid API keys - https://dashboard.plaid.com/account/keys
PLAID_CLIENT_ID = os.getenv('PLAID_CLIENT_ID')
# Use 'sandbox' to test with Plaid's Sandbox environment (username: user_good,
# password: pass_good)
# Use `development` to test with live users and credentials and `production`
# to go live
PLAID_ENV = os.getenv('PLAID_ENV','sandbox')
print(PLAID_CLIENT_ID)
The output I am receiving is entercharhere
and None
EDIT
I wound up switching my declaration of variables to send them to the environment using this:
os.environ['PLAID_CLIENT_ID']='entercharhere'
os.environ['PLAID_ENV']='sandbox'
Is this the best way to do it?
Works perfectly:
import os
os.environ['SOMEVAR'] = 'bla'
print(os.getenv('SOMEVAR'))
# in your shell: export SOMEVAR1="blabla"
print(os.getenv('SOMEVAR1'))
Gives:
bla
blabla
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.