How to add environment variables into replit in python

how do you create environment variables in python

project link: https://replit.com/@LevKnettle/fox-bank-secure-login?v=1

To add secrets (environment variables) you select Secrets from the tools menu.

Then to use them in your code you have to do this.

import os

my_secret = os.getenv("MY_SECRET")
2 Likes

okay but when other people run this project, the os.getenv() function returns None.

Do you mean when they fork it, or just when it is run? If you mean forking then that is on purpose that they can’t see the values.

when people run it, but not have forked it, os.getenv returns None

Can you share a link to the repl? Because I’m not sure why that would be.

Only the repl owner and people with edit access to a repl will have access to environment variables added using the Secrets pane. Would you like everyone to have the environment variables?

4 Likes

no the program cant access environment variables.

the project link is https://replit.com/@LevKnettle/fox-bank-secure-login?v=1

You are trying to use the getenv method like this getenv["password"] but you need parenthesis getenv("password")

image

3 Likes

That still won’t change the fact that the cover page CANNOT access variables set in the Secrets tab. Which seems to be what they want, feel free to correct me if I’m wrong.

1 Like

so how do I set environment variables

You want them to also be set on the cover page correct?

I want to set them in secrets tab

Have you opened the secrets tab?
image

If you set them in the secrets tab, the cover page CANNOT access them.

so how do I set them so cover page can acces them

yes that is the point, the problem was that the program itself couldnt access the secrets

No, the point was cover page couldn’t access them.

You could set them under [env] in .replit, but be aware that anyone can read them then.