Problem when accessing email address in .env file using dotenv's load_dotenv

Hi everyone, hope you all are staying safe :smiley:

I’ve been searching the internet for the solution but I can’t seem to find what is the issue with my code. (update: I’m coding a simple web scrapper)

While using the python-dotenv 0.15.0 python package, I can’t get the email address from the .env file

.env file

USERNAME="name@domainname.com"
PASSWORD="password"
AUTH_URL_FACULTY="https://url.com"
AUTh_URL_GENERAL="https://url.com"
ENROLLED_CORE_COURSE_URL="https://url.com"
ENROLLED_GENERAL_COURSE_URL="https://url.com"
CORE_COURSE_URL="https://url.com"
GENERAL_COURSE_URL="https://url.com"

python file (I used this file to test how to use a value from the .env file)

import os
from dotenv import load_dotenv
load_dotenv('.env')
print(os.getenv("USERNAME"))

The output will show User instead of the email address.

Thanks for reading the question, any tips for the reason why is this happening will be much appreciated. Also, keep staying safe.

Hey @Leonlit,

There is not a lot to look at in these 2 code blocks you have given us. Right now, I don’t know if you have imported the os modules or not. I don’t know if there is other variable values inside the .env files. I don’t know what package you are using exactly, there is a couple of dotenv packages for python out there. I don’t know if there is other part of the code that could cause this to happen.

Unless the whole python and .env files contains only what you’ve given us inside the 2 code blocks, Please give us more specifics.

Here’s an example of a repl I tried and it worked perfectly fine:

| https://repl.it/@JoshuaPelealu/FirsthandCharmingIntercept

Thank you and Happy Coding.

1 Like

Good day @Catalactics, sorry for not specifying the package that I used and I seem to forget to paste one line from my code. I’ve updated the post and it seems that your example code and compared to mine, they’re the same. Another thing is that is it possible that the package took the value from my window’s environment? Because I named my computer’s username as User… Thank you.

Well, I solved the problem, the package indeed took the value from my window environment. So I changed the variable name to ACC_USERNAME instead of USERNAME. Anyway thanks @Catalactics :smiley:

1 Like