I am really new to the space so sorry if my questioning is bad or I ask novice questions. also thanks in advance for the repliers!
what I am trying to do?
I am trying to access my environment variable from the .env file and print its value in the terminal.
What is the issue?
When I run the script in the terminal I keep getting the error
I checked a few forums and the dotenv paper about the issue but none helped me solve this
some more info:
I am using windows 10
The version of dotenv is 0.20.0
I downloaded it using
python -m pip install python-dotenv
.env file –
export PRIVATE_KEY = 0xc3c4e4fe27d8e6b06710e713878e4488c034ce346a578fdfa78bb3d335130eec
the python file –
from dotenv import load_dotenv import os load_dotenv() print(os.getenv("PRIVATE_KEY"))
first thanks for the replies! Didn’t expect an answer in less than a 24h, it really feels nice.
So I solved my issue but it wasn’t after removing the "export" in the .env file (I tried with and without it both gave the same results in the terminal), I had to specify the full path of the .env file in the load_dotenv(), apparently I had to specify it but many code samples I saw in forums didn’t need to do it I wonder why…
anyway here is the new code…
the python code –
the .env file –
by the way it’s not a real private key
I am not gonna close this thread yet, I still have a question regarding this issue as it was more luck that helped me solve this…I don’t want to see this issue pop up again for me in the future so if anyone can answer my question it would be great!
At some point before I found the solution I ran the python script in the terminal and got a random private key (I don’t have it pictured sadly), it might had been a key I set in the past but then I checked if I had other .env files in the folder but I had none I also didn’t have any environment variables in System Properties > Advanced > Environment Variables on windows so where does dotenv gets the key values by dafault? also After that I reopened vscode and tried again but I got a
Answered By – boten500