Ask coding questions

← Back to all posts
How to get environment variables in python with the new way in repl?
h
lunaticsatoshi (0)

So I have been trying to access environment variables that I have set using the new Secrets feature on the sidebar but I can't seem to retrieve them inside my program. Whenever I am running the program manually by typing python main.py on the shell trying to access the environment variable using os.getenv('YOUTUBE_API_KEY') it returns None. But it works fine on the console. if anyone can help i would be really grateful!! :)

Answered by Bookie0 (6258) [earned 5 cycles]
View Answer
Comments
hotnewtop
Bookie0 (6258)

According to the docs, you can't get access environment variables in the shell:

Note that you cannot set environment variables for repls that have only a frontend, e.g. HTML repls. Also note that environment variables set through the UI are not available in the Replit shell (e.g. with echo $MY_VARIABLE).

robowolf (548)

Here's a link that explains everything about the new way.