I am creating a simple app that connects to an API and stores specific data into a list. In order to connect to the API, I must do BasicAuth with an email and password. Whenever I hardcode my email and password into the Python script, it works perfectly, however whenever I store these values in a .env
file and do os.getenv('EMAIL')
, I am getting a 401 error. I proceeded to print out the value of EMAIL and PASSWORD when EMAIL = os.getenv('EMAIL')
and PASSWORD = os.getenv('PASSWORD')
but it is printing None in the console. Here is my code in the Python script:
load_dotenv()
EMAIL = os.getenv('EMAIL')
PASSWORD = os.getenv('PASSWORD')
Here is what my .env file looks like:
EMAIL = importantemail@mydomain.com
PASSWORD = secret_password
The two files are in the same folder but I am thinking that I need to do something like pointing my working directory to the folder that has the script and the .env file. This is my first full-fledged project so I believe that I am missing something obvious.