← Back to Community
error with env files please help (might be repl's fault)
Profile icon
BenjaminNamika1

I found an error with .env files. env files do not work in python if you click on the "box with arrow" to run the program in a new window. Then the os.getenv("key") returns None even if you have something with a key of none. for example:
click on this link https://error.benjaminnamika1.repl.run/ and it will print None
while if you look run the code- https://repl.it/@BenjaminNamika1/Error (the code for the above program) then you will see it will print "hello everyone". in the file the actual .env file won't be displayed so a created a file called env wich will contain the exact same text as the .env file.
I think this might be a problem with repl....

Answered by ash15khng [earned 5 cycles]
View Answer
Voters
Profile icon
RiceIeaten
Profile icon
0xhh
Profile icon
cristianosilva4
Profile icon
AK11NP
Profile icon
BenjaminNamikas
Profile icon
BenjaminNamika1
Comments
hotnewtop
Profile icon
ash15khng

The code prints "None" for me?

Profile icon
BenjaminNamika1

@ash15khng on the first script it will because you are in the .run and it can't access the .env files, so it return None. the second script returns "hello world" becuase the actual file can access the.env
P.S. i made a copy of the .env and put it in a env file

Profile icon
ash15khng

@BenjaminNamika1 On the second link it also prints "None"?

Profile icon
BenjaminNamika1

@ash15khng well for me it prints 'hello everyone' so maybe the .env files are only accessible by me when it is not in .run, so thank you now i understand and can base my program off my new knowladge

Profile icon
ash15khng

@BenjaminNamika1 It's supposed to be able to run for everyone I think? Anyways glad you learnt something! I'll link this thread to the repl bugs page in case this is a bug (I'm really not sure)

Profile icon
BenjaminNamika1

@ash15khng thanks. I thought it was for everyone too....
Also i didn't know that there was a repl bugs page.
Thanks again

Profile icon
mat1

repl.run links and logged-out users can't access the env file due to security reasons.

Profile icon
BenjaminNamika1

@mat1 what do you exactly mean when i was runing it in a new window i was loged in? i know that you can's see the .env so i created a copy called "env"

Profile icon
[deleted]

This is because when you use .env only the creator can see what they stored there. I think these are used to create secure passwords or something.