This feels like a dumb question, but how should I be calling app-level environment variables from a python script hosted on app platform? Specifically, I can’t seem to pass the original value of the environment variable to my script after I set the variable to “encrypted” in the app’s control panel. That is, it appears that the encrypted value of the environment variable is getting passed to my app, which is strange because the unencrypted value shows up when I look it up on the console. I’m using this code:
import os
PASSKEY = os.environ.get('PASSKEY')
Any idea what’s going on?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Hey!
Not a dumb question at all! In fact, it’s an important aspect of working with environment variables, especially when dealing with sensitive data like encrypted variables in a cloud environment such as DigitalOcean’s App Platform.
When you set an environment variable as “encrypted” in the DigitalOcean App Platform control panel, it’s encrypted at rest for security purposes and is also obscured from all logs. However, when your application runs, DigitalOcean automatically decrypts these variables, and they should be available to your application in their original, unencrypted form. This means that your Python script should be able to access the unencrypted value of
PASSKEY
directly, without needing to do any decryption manually.Your current approach to accessing the environment variable in Python is correct:
Here are a few things to check and consider:
Ensure that your app has been redeployed after setting the encrypted environment variable. Changes to environment variables often require a redeployment for them to take effect.
Double-check the name of the environment variable. It needs to match exactly between what’s set in the DigitalOcean control panel and what your script is trying to access.
Make sure that the environment variable is set at the appropriate scope. If it’s an app-level variable, it should be available to all components of your app. If it’s set at the component level, it will only be available to that specific component.
To debug, you might temporarily print out the environment variable in a safe, controlled environment (ensuring no sensitive data is exposed in logs or output). This can confirm if the variable is being passed correctly to your application.
Let me know how it goes!
Best,
Bobby