Forums

problem with env variables in always on tasks

Hi, I'm having an issue dealing with env variable on a script that is supposed to run on always-on-task. In this script i m using api key and secret that I registered in my virtual env. The script runs just fine in the console but when i'm launching it to the always-on-task, it fails. I use : workon snapbet && python3 -u /home/Snapbet/Bot/bot.py It works though when I hard code the key and secret in my code, which is clearly not ideal. Is there a fix for that ? Thank you !

How do you set your env vars?

export NAME=VALUE

If you're setting environment variables in a console, that has no effect on the environment variables that are set on alwayson tasks. If you set your environment variables in your virtualenv postactivate script, then they will be available after you activate your virtualenv: https://help.pythonanywhere.com/pages/environment-variables-for-web-apps/

Thanks a lot, I thought this page described a fancy way of doing just an export. I will try that !

Let us know if you have any other problems.