admin管理员组文章数量:1186687
This is the content of .env file
YOUTUBE_API_KEY=SyCnieNj
# old-api-key
# YOUTUBE_API_KEY=AIzayCno
When i try to use YOUTUBE_API_KEY
the old api is loaded
This is the part of the python code:
import os
import json
import time
import googleapiclient.discovery
import googleapiclient.errors
from dotenv import load_dotenv
# Load API keys
load_dotenv()
# YouTube API setup
YOUTUBE_API_KEY = os.getenv("YOUTUBE_API_KEY")
Even after removing all the comment line from .env file os.getenv("YOUTUBE_API_KEY")
is still loading old api key
Can anyone explain the issue here?
When I changed the api key in .env and reloaded the script the script is still using the old api key
This is the content of .env file
YOUTUBE_API_KEY=SyCnieNj
# old-api-key
# YOUTUBE_API_KEY=AIzayCno
When i try to use YOUTUBE_API_KEY
the old api is loaded
This is the part of the python code:
import os
import json
import time
import googleapiclient.discovery
import googleapiclient.errors
from dotenv import load_dotenv
# Load API keys
load_dotenv()
# YouTube API setup
YOUTUBE_API_KEY = os.getenv("YOUTUBE_API_KEY")
Even after removing all the comment line from .env file os.getenv("YOUTUBE_API_KEY")
is still loading old api key
Can anyone explain the issue here?
When I changed the api key in .env and reloaded the script the script is still using the old api key
Share Improve this question edited Jan 26 at 10:52 VLAZ 29k9 gold badges62 silver badges82 bronze badges asked Jan 25 at 17:10 Anurag JainAnurag Jain 32 bronze badges New contributor Anurag Jain is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct. 2 |1 Answer
Reset to default 0I think the load_dotenv
function fetches the environment variable's cached value. It can be resolved by enabling an override prop in the load_dotenv
function.
using this you can fetch the correct value whenever it is updated in the correct order, I think this will help(taken from the docs of python dotenv - https://pypi.org/project/python-dotenv/) -
load_dotenv(override=True)
本文标签:
版权声明:本文标题:python - When I edit a .env file, and try to use the new variable the old one gets loaded - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738350410a2078864.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
#YOUTUBE_API_KEY=AIzayCno
comment actually gets parsed – roganjosh Commented Jan 25 at 17:16os.getenv("YOUTUBE_API_KEY")
is still loading old api key – Anurag Jain Commented Jan 25 at 17:41