Quantcast
Channel: Active questions tagged config - Stack Overflow
Viewing all articles
Browse latest Browse all 5049

Python-Config package can't find my .env file and says I haven't declared password, host, and user variables when I have

$
0
0

I have a python file I am working on to access a company database remotely using decouple, psycopg2, and pyathena. In order to do this, I have to use the DB_password, db_host, and db_user fields. the file I am working on is 2 levels down from the root directory and relies on my .env file to populate the passwords. my .env file is in the root directory.

here is the code i'm using to call the passwords/.env file:from decouple import config

import psycopg2import boto3 import osimport pyathenadb_pw = config('DB_PW')db_host = config('DB_HOST')db_user = config('DB_USER')conn = psycopg2.connect(host=db_host, database='my_company', user=db_user, password=db_pw)

my .env file is in the root directory and looks like this (with each variable on a new line):

DB_USER="user"DB_HOST="host address"DB_PW="password"

when I run the code, the imports work just fine, but then when I run the code below the imports grabbing the configs, it says "UndefinedValueError: DB_PW not found. Declare it as an envvar or define a default value."

I have defined the value, though. So that makes me think either I've set up my .env file incorrectly, and it's in the wrong place, but it's in the root directory. any ideas?


Viewing all articles
Browse latest Browse all 5049

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>