Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

environment variables not updating

I am using the dotenv package. I had a key that I had saved in my .env file but I updated it to a new key, but my script still outputs the old key. I have the ".env" file in the root directory.

I thought that by using load_dotenv() that it's taking in the new keys whatever they may be at the current state in time and saving it to be used in the script. What am I doing wrong?

import os
from dotenv import load_dotenv
import praw
load_dotenv()


reddit = praw.Reddit(client_id=os.getenv('reddit_personal_use'),
                     client_secret=os.getenv('reddit_api_key'),
                     user_agent=os.getenv('reddit_app_name'),
                     username=os.getenv('reddit_username'),
                     password=os.getenv('reddit_pw'))
like image 295
hope288 Avatar asked Sep 06 '25 17:09

hope288


1 Answers

I had to set override=True

load_dotenv(override=True)

load_dotenv does not override existing System environment variables. To override, pass override=True to load_dotenv().

like image 71
hope288 Avatar answered Sep 09 '25 08:09

hope288