Forums

Environment variables issues despite following instructions successfully

Hello,

Once again, I have an issue that I'm stumped on. I'm trying to set up a password reset page in a blog using django. I added the following to the settings.py file:

EMAIL_HOST_USER = os.getenv('EMAIL_USER')
EMAIL_HOST_PASSWORD = os.getenv('EMAIL_PASSWORD')

and the following in the .env file located in the project directory:

export EMAIL_USER="fakeemail@gmail.com"
export EMAIL_PASSWORD="NotActualPassword"

If I were to use the bash console, load the webapp virtual environment and run the following code:

>>import os
>>EMAIL_HOST_USER = os.getenv('EMAIL_USER')
>>EMAIL_HOST_USER

I get, as a result:

>>fakeemail@gmail.com

So, despite all this seemingly working in theory, when I do try to reset the password it gives me an SMTPSenderRefused error.

I can have the password reset issue work without problems by not using environment variables in settings.py, as so:

EMAIL_HOST_USER = "fakeemail@gmail.com"
EMAIL_HOST_PASSWORD = "NotActualPassword"

However, I want the environment variable to work because I want to also use AWS and not have the user secret access key show up in the code.

P.S. I don't know if it helps, but I've set up the virtual environment to load in the postactivate script, and get the following:

echo $EMAIL_USER
fakeemail@gmail.com

Is there anything that I could be missing?

You need to load the environment in your web app. See http://help.pythonanywhere.com/pages/environment-variables-for-web-apps/

Hello I am still having issues and I am just not sure what is wrong :( I have gone through all of the forums and now I am ending up with this error.

I know there is an issue with how I set up my virtual env or something because the app works perfectly If I dont use the variables

On my current iteration, here is my error message:

ModuleNotFoundError: No module named 'dotenv'

Please help!

Do you have it installed in your virtual environment?