On my Django website the user is able to upload images. I am trying to implement a feature for them to search for images based on what the images are.
To do this I decided to use Google Vision AI. I was able to get this API to work in a separate project. However, when I try implementing the API into my Django project it doesn't work. (Error pasted at the end).
In my test project I had to create an environment variable for the Google Application Credentials, this is what it looked like:
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = r'venv/filename.json'
After reading several articles on how to implement environment variables into Django, this is what I implemented thus far into settings.py:
env = environ.Env()
environ.Env.read_env()
GOOGLE_APPLICATION_CREDENTIALS = env('GOOGLE_APPLICATION_CREDENTIALS')
As a test to see if environment variables were working at all in my project, I stored the SECRET_KEY into the .env file and I got it to work. Here is what that looked like along with my .env file
.env
GOOGLE_APPLICATION_CREDENTIALS=venv/filename.json
SECRET_KEY=this-is-my-secret##key
SECRET_KEY:
SECRET_KEY = env('SECRET_KEY')
The error I am getting:
DefaultCredentialsError at /images/
File venv/filename.json was not found.
Please help me to figure out why my environment variable is not working
The problem with my program was that I was searching for the environment key in the wrong directory. Once I moved the file to the proper directory/ changed directory through my code all was well.