environment variables not updating
Asked Answered
R

1

21

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'))
Ruminant answered 26/8, 2020 at 1:47 Comment(0)
R
49

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().

Ruminant answered 26/8, 2020 at 2:9 Comment(1)
Thank you for adding a solution, saved me a lot of time:)Spencerianism

© 2022 - 2024 — McMap. All rights reserved.